3 Arrays Part-1
3 Arrays Part-1
CS-201
Lecture # 03
Data Structure
vs
Storage Structure
• Data Structure : The logical or mathematical model
of a particular organization of data
• Storage Structure : Representation of a particular
data structure in the memory of a computer
• Data Structure
– Linear
– Non-Linear
3
Representation in Memory
4
Operation on Linear Structure
5
Array
6
Linear Arrays
7
Linear Arrays
8
Linear Arrays
9
Representation of Linear Array in Memory
1000
1001
1002
1003
1004
1005
:
Computer Memory
10
Representation of Linear Array in Memory
12
Example 1
200 LA[0]
Find the address for LA[6] LA[1]
201
Each element of the array
occupy 1 byte 202 LA[2]
203 LA[3]
204 LA[4]
205 LA[5]
206 LA[6]
207 LA[7]
200
Find the address for LA[15] LA[0]
201
Each element of the array
occupy 2 bytes 202
LA[1]
203
204
LA[2]
205
206
LA[3]
207
• One-Dimensional Array
• Two-Dimensional Array
• Three-Dimensional Array
15
Two-Dimensional Array
• A Two-Dimensional m x n array A is a
collection of m . n data elements such that
each element is specified by a pair of
integers (such as J, K) called subscripts
with property that
1 ≤ J ≤ m and 1 ≤ K ≤ n
16
2D Arrays
The elements of a 2-dimensional array a is
shown as below
20
2D Array in Memory
A Subscript A Subscript
(1,1) (1,1)
(2,1) Column
1 (1,2) Row 1
(3,1) (1,3)
(1,2) (1,4)
(2,2) Colum n 2 (2,1)
(3,2) (2,2) Row
(1,3) 2
(2,3)
(2,3) Colum n 3 (2,4)
(3,3) (3,1)
(1,4) Column (3,2) Row 3
(2,4) 4
(3,3)
(3,4) (3,4)
22
2D Array (Row Major)
A5x6 Kth
Column
Jth A[J][K]
Row
23
2D Array (Column Major)
A5x6 Kth
Column
Jth A[J][K]
Row
24
2D Array Example
25