0% found this document useful (0 votes)
89 views43 pages

Chapter 1 - Memory ADT & Addressss

1. The document discusses different types of computer memory and how data is stored in memory. It covers main memory, cache memory, persistent storage, and how data types reserve space in memory. 2. It describes four main data type groups - integers, floating-point, characters, and booleans - and examples of specific data types like byte, short, int, long, float, and double. 3. Choosing the appropriate data type depends on the nature of the data and ensuring enough memory is reserved without wasting space. Integers are used for whole numbers while floating-point represents real numbers.

Uploaded by

Hydie Cruz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views43 pages

Chapter 1 - Memory ADT & Addressss

1. The document discusses different types of computer memory and how data is stored in memory. It covers main memory, cache memory, persistent storage, and how data types reserve space in memory. 2. It describes four main data type groups - integers, floating-point, characters, and booleans - and examples of specific data types like byte, short, int, long, float, and double. 3. Choosing the appropriate data type depends on the nature of the data and ensuring enough memory is reserved without wasting space. Integers are used for whole numbers while floating-point represents real numbers.

Uploaded by

Hydie Cruz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 43

Data Structure and Algorithm

Chapter 1 – Memory, Abstract Data


types, and Address
Intro / Question?

 What is the maximum number of tries to find


your name in million of list? 20
 If the structure of list make it easy to search
and if search structure with an efficient
searching teaching.
 Searching list is one of the many ways data
structure help manipulate data.
Tour of Memory

Computer Memory divided into 3 sections:


1. Main memory

2. Cache memory in CPU

3. Persistent storage
BUS (Simplified Architecture)
Cont. tour of Memory

1. Main memory – (RAM)stores instructions


and data . Volatile
2. Cache Memory – in the cpu is used to store
frequently used instructions and data .
 A segment of cpu cache is called a
register.
A register is a small amount of memory within the CPU
that is used to temporarily store instructions and data
Cont. tour of Memory

 A bus connects the CPU and main


memory.
 A bus is a set of etched wired on the
motherboard that is similar to a highway
and transports instructions and data
between the CPU, main memory, and
other devices connected to a computer
Cont. tour of Memory

3. Persistent storage – is an external storage


device such as hard disk that stores
instructions and data.
 Nonvolatile

 Persistent storage is commonly used by the


operating system as virtual memory.
 Virtual memory is a technique by os uses to
increase the main memory capacity beyond
the random access memory (RAM) inside the
computer
Cont. tour of Memory

 When main memory is exceed, the os


temporarily copies the content of a block of
memory to persistent storage.
 If a program needs access to instructions or
data contained in the block, the os switches
the block stored in persistent storage with a
block of main memory that isnt being used.
Storage device hierarchy

Registers
Cache
Main Memory
Electronic disk (hard disk)
Magnetic disk
Optical disk
Magnetic tapes
Cont. tour of Memory

 CPU cache memory is the type of memory


that has the fastest access speed.
 A second close is main memory.
 Persistent storage is a distant third because
persistent storage device usually involve a
mechanical process that inhibits the quick
transfer of instructions and data.
Data Structure and Memory

 Data used by our program is stored in


memory and manipulated by various data
structure technique at main memory and how
data is stored in memory before exploring
how to manipulate data using data structure.
 Memory is a bunch of electronic switches
called transistors that can be placed in one of
two states: ON or OFF.
Data Structure and Memory

 Each state is meaningless unless, we


assigned a value to each state (binary
number systems)
 Binary number system : consists of two digits
 Each switch off (zero), switch on (one)
 This means that one transistor can represent
one of the two digits.
Example

Switch One Switch Two Decimal

0 0 0
0 1 1
1 0 2
1 1 3
The binary Number System

 Is a way to count things and perform


arithmetic
 Both these numbers can be used to perform
addition, subtraction, multiplication and
division
Reserving Memory

 Although a unit memory holds a byte, data


used in a program can be larger than byte
and require 2, 4, or 8 byte to be stored in
memory
 Before any data can be stored in memory, we
must tell the computer how much space to
reserve for data by using an abstract data
Type (ADT)
Reserving Memory

 ADT is a keywords of a programming language that


specifies the amount of memory needed to store
data and the kind of data that will be stored in that
memory location.
 However, ADT does not tell the computer how many
bytes to reserve for the data
 The number bytes reserved for an ADT varies,
depending on the programming language used to
write the program and the type of computer used to
compile the program.
Reserving Memory

 ADT types in Java have a fixed size in order


for programs to run in all java runtime
environment.
 In C and C++, the size of ADT is based on
the register size of the computer used to
compile the program.
 The int and float data types are the size of
the register.
Reserving Memory

 A short data type is half of the size of an int,


the long data type is double the size of an int.
 Ex:case of tomatoes

You can call the warehouse managers and say


that you need to reserve enough shelf space
to hold five cases of tomatoes. The
warehouse managers knows how many
shelves to reserve because she/he knows the
size of a case of tomatoes.
Reserving Memory

 ADT tell the computer to reserve space for an


integer by using the ADT int. The computer
already know how much memory to server to
store an integer.
 Why is it important because manipulate data
of some ADT types differently than data of
other ADT.
Reserving Memory/ Data Types
Data Type Size in Bits Range of Group

Values

byte 8 128 to 127 Integer

short 16 -32,768 to 32,767 Integer

int 32 -2,147,483,648 to Integer

2,147,483.65

long 64 -9,223,372,036,854,775,808 Integer

to 9,223,372,036,854,775,807

char 16(unicode) 65,536 (unicode) Characters

float 32 3.4e-038 to 3.4e+038 floating point

double 64 1.7e-038 to 1.7e+038 floating point

boolean 1 0 or 1 Boolean
Criteria used on how to ADT

 Best suit on the data you want to store, the


use of ADT in declaration statement to
declare the variables.
 Variable is reference memory location that
you reserved using the declaration.
 You should always reserve the proper
amount of memory needed to store data
because you might lose data if you reserve
too small in a space.
Abstract data type Groups

Four data type groups ;


 Integer – stores whole numbers and signed
numbers. Used for storing the number of
pesos in our wallet without a decimal number.
 Float-point Stores real numbers (fractional
values). Used for storing bank deposit
(centavos can quickly add up to a few
pesos.)
Abstract data type Groups

 Character – stores a character. Ideal for


storing names of things.
 Boolean – stores true or false value. Ideal
choiced for storing yes or no response to a
question.
Integers

 Integers consists of four ADT used to reserve


memory to store whole numbers:
 Byte, short, int and long
 Depends on the nature of the data,
sometimes an integer must be stored using a
positive or negative sign such as 10+, or -5.
 An integer that is stored with a signed is
called signed numbers, an integer stored
with a sign is called an unsigned numbers.
Integers

 C and c++ support unsigned integers.


 Java does not
 An unsigned integer is a value that is implied
to be positive sign. The positive sign is not
stored in memory.
 All integers in Java is reprsented with a sign.
 Zero is stored as a positive number.
Byte

 Byte ADT is the smallest ADT in the integer


group and is declared by using the keywords
byte.
 Programmers typically use a byte ADT when
sending data to and receiving data from a file
or across a network.
 Byte is commonly used when working with
binary data that may not be compatible with
other ADT
Short ADT

 Short is ideal for use in programs that runs on


16-bit computers. But most of those
computers had been replaced by 32-bit and
64-bit computers.
 Short is the least used integer in adt
 Short is used to store an integer in a program
that runs on a very old computer.
Int ADT

Most frequently used for a number of reasons:


 For control variables in control loops

 In array indexes

 When performing integer math


Long ADT

 Is used whenever using whole numbers that


are beyond the rangeof an int data type.
 Use when storing net worths of Bill Gates,
Floating-Point

 Are used to store real numbers in a


memory.
 A real number contains a decimal number.
 2 kinds of floating point data types
1. Float
2. double
Floating-Point

 Float ADT is a single precision number


 Double is a double precision number.
Precision of a number of places after the
decimal point that contains an accurate rate.
 Floating point refers to the way decimals are
referenced in memory,
Floating-Point

 2 parts of floating point


1. The real numbers – stores a whole numbers
2. Position – the decimal point within the whole
numbers.
Floating-Point

 Float ADT is used for real number that


requires single precision such as Currency.
 Single precision means the value is precise
up to 7 digits to the right of the decimal.
 Ex; divide $53.50 to 7 digits, each person will
get 3.147058823529.
 Digits to the right of 3.1470588 are not
guaranteeed to be precised because of the
way float is stored in memory.
Floating-Point

 Double ADT is used to store real numbers


that are very large or very small and require
double the amount of memory that is
reserved with a float ADT
 Use when need to store a decimal value with
more than 7 digits decimal value to the right
of the decimal must be accurage
Characters

 Is represented as an integer value that


correspond to a character set.
 A character set assigns an integer value to
each character, punctuations, and symbols
used in a language.
 Ex: A is stored in memory as the value 65,
which corresponds to a letter A in a character
set
Characters

 Computer knows how to treat value of 65 as


the letter A, than number 65 because of
memory was reserved using the char ADT.
 The keywords char tells the computer that the
integer stored in that memory location is
treated as character and not a number.
Characters
2 characters used in programming;
1. American Standard Code for Information Interchange (ASCII) –
granddaddy (old) character sets and uses a byte to represent a
maximum number of 256 characters.
 However, serious problem was evident after years of using
ASCII. Many language such as Russian, Arabic, Japanese and
Chinese is more than 256 characters.
 To resolve that a character is used called UNICODE.

1. UNICODE
 Unicode – 2 bytes to represent each
character. Choose a char whenever we need
to store single character in memory .
Boolean

 Reserve memory tostore a boolean value,


with is true or false represents as a zero or
one.
Memory Address

 Imagine main memory as a series of endless


boxes organized into groups of eight.
 Each boxes holds zero or one.
 Each group of eight boxes is assigned a
unique number called memory address.
 Memory address is indirectly or indirect used
within a program to access all eight boxes.
Real Memory Address

 Are represented in 32- bit or 64-bit number,


depending on the computer’s operating
system and are represented as a
hexadecimal value.
 The hexadecimal value are used to count and
they are used in arithmetic.
 0 to 9, A through F
Adt and memory Address

 Each byte has its own memory address,


might assume that has two memory address
because it uses 2 byte of memory. That is
not the case.
 The computer uses the memory address of
the first byte to reference any ADT that
reserves multiple byte Memory.

You might also like