Professional Documents
Culture Documents
Introduction To Data Structure
Introduction To Data Structure
1 4 5 6
2 7 8 9
3 10 11 12
R ow 0 R ow 1 R ow 2 R ow 3
C o lu m n 0 C o lu m n 1 C o lu m n 2
Address Calculation
For a two dimensional array, a[r][c] where r =
number of rows and c = number of columns, the
location of an element a[i][j] in the array can be
calculated as:
Row Major Representation : address of a[i][j]
= Base-address + i*c*element size + j*element size
= Base-address + (i*c+j) * element size
e.g.
address of m[1][2]
= 1000 + (1*3+2) * sizeof (int)
= 1000 + 10
= 1010
Address Calculation
Column Major Representation : address of a[i][j]
= Base-address+ j*r*element-size + i*element–size
= Base-address+(j*r + i)* element–size
e.g. :
address of m[1][2]
= 1000 + (2*4+1) *sizeof (int)
=1000 + 18
=1018
End of Presentation