Unit-2 Array Representation
Unit-2 Array Representation
Array
Linear Data Structure
marks[0] marks[1] marks[2] marks[3] marks[4] marks[5] marks[6] marks[7] marks[8] marks[9]
Here
A is the array
k is the index of the element of which we have to calculate the address
BA is the base address of the array A
w is the word size of one element in memory, for example, size of int is 2
Here,
lower_bound = 0, upper_bound = 7
Therefore, length = 7 – 0 + 1 = 8
data_type array_name[row_size][column_size];
int marks[3][5];
Loc (A [ i , j ]) = L0 + (j-1)*n + (i – 1)
Column - 5
Column - 7
Column - 6
Column - 4
Column - 1
Column - 2
Row - 1 0 0 0 2 0 0 1 0 Terms 0 1 2 3 4 5 6 7 8
Row 1 1 2 2 2 3 3 4 4
Row - 2 0 6 0 0 7 0 0 3
Column 4 7 2 5 8 4 6 2 3
Row - 3 0 0 0 9 0 8 0 0 Value 2 1 6 7 3 9 8 4 5
Row - 4 0 4 5 0 0 0 0 0
Linear Representation of given matrix
4x8
6x7 2 1 2
2 4 7
Memory Space required to store
6x7 matrix 2 5 8
2 7 4
42 x 2 = 84 bytes
3 1 10
4 3 12
https://www.youtube.com/watch?v=IxFChpxFztg