ppt.array
ppt.array
Instruction + Data
Data Structure
It is a way of organizing data that considers not
only the items stored but also the relationship of
each data.
K. Adisesha 3
Definition
Primitive data structures
K. Adisesha 4
Data Structure
Integer Hash
Logical
Real Number
Enumeration
Character
Partial
K. Adisesha 5
Dynamic memory allocation and pointers
Recursion
Searching and Sorting
Stack
Queue
Linked list
Tree
K. Adisesha 6
Basic Data Type Simple Type
K. Adisesha 7
Structured Type Array Type
ArrayX [ j ]
Element / Subscript / Index
Array Name
K. Adisesha 8
Structured Type Array Type
Example:
Grade [ j ] Grade [ 0 ] = 95
Grade [ 5 ] Grade [ 1 ] = 85
Grade [ 2 ] = 75
Grade [ 3 ] = 100
Grade [ 4 ] = 65
K. Adisesha 9
Structured Type Array Type
int ArrayX [ j ,
k ]
Base type index
Array Name
K. Adisesha 10
Structured Type Array Type
K. Adisesha 13
Memory Map
Element Address
s 3 245
4 249
Locate 5 253
6 257
7 261
8 265
K. Adisesha 14
Exercise
An automobile company uses array AUTO to
record the number of automobile sold each year
from 1932 to 1996. Locate AUTO[1980]. Assume
801 as starting address with 5 words long. Also find
the length of the array AUTO.
ANSWER:
Loc[1980] = 1041
NE = 65
K. Adisesha 15
Exercise
Given a 4x5 array with [-3..0, 2..6) index,
starting address is 81 with 2 words per memory cell.
Locate [-1,5] using row major and column major
representation.
To get the number of elements in an
array
M = UB1 – LB1 + 1 NE = M x N
N = UB2 – LB2 + 1
-3 81 83 85 87 89
R
O -2 91 93 95 97 99
W
10 ROW
-1 103 105 107 109 MAJOR
1
Locate
11
0 113 115 117 119
1
K. Adisesha
BAC17
Memory Map
COLUM
N
2 3 4 5 6
-3 81 89 97 105 113
R
O -2 83 91 99 107 115
W
COLUMN
-1 85 93 101 109 117 MAJOR
Locate
0 87 95 103 111 119
K. Adisesha
BAC18
Exercise
When storing a two-dimensional array “a” with ten rows
and ten columns in continuous memory space in the direction
of rows, what is the address where a [5,6] is stored? In this
question, the address is represented in decimal numbers.
Addres
s
100
a [1,1]
101
102
a [1,2]
103
K. Adisesha 19