MEMORY REPRESENTATION
OF MATRIX
Row-Major Order
Column-Major Order
7
ROW MAJOR
In this method the elements are stored row wise.
i.e. n elements of first row are stored in first n locations, n elements of
second row are stored in next n locations and so on.
8
A[0][0]A[0][1]A[0][2]A[0][3]
A[1][0]A[1][1]A[1][2]A[1][3]
A[2][0]A[2][1]A[2][2]A[2][3]
A[0][0]200
A[0][1]201
A[0][2]202
A[0][3]203
A[1][0]204
A[1][1]205
A[1][2]206
A[1][3]207
A[2][0]208
A[2][1]209
A[2][2]210
A[2][3]211
ElementAddress
COLUMN MAJOR
In this method the elements are stored column wise.
i.e. m elements of first column are stored in first m locations, m elements of second
column are stored in next m locations and so on.
9
A[0][0]A[0][1]A[0][2]A[0][3]
A[1][0]A[1][1]A[1][2]A[1][3]
A[2][0]A[2][1]A[2][2]A[2][3]
A[0][0]200
A[1][0]201
A[2][0]202
A[0][1]203
A[1][1]204
A[2][1]205
A[0][2]206
A[1][2]207
A[2][2]208
A[0][3]209
A[1][3]210
A[2][3]211
ElementAddress
ADDRESS CALCULATION
Row Major System:
Address of A [ I ][ J ] = B.A + [( I –Lr )* N + ( J –Lc ) ]*Size
Column Major System:
Address of A [ I ][ J ] = B.A + [( I –Lr ) + ( J –Lc )*M]*Size
10
ADDRESS CALCULATION
B.A= Base address
I= Row subscript of element whose address is to be found
J= Column subscript of element whose address is to be found
Size= Storage Size of one element stored in the array (in byte)
Lr= Lower limit of row/start row index of matrix, if not given assume 0 (zero)
Lc= Lower limit of column/start column index of matrix, if not given assume 0
(zero)
M= Number of row of the given matrix
N= Number of column of the given matrix
Usually number of rows and column of a matrix are given like A[10][15],
A[5][2] but if it is given as A[Lr......Ur][Lc.......Uc]
So in this case number of rows and columns will be calculated as
rows(M)= (Ur-Lr)+1
column(N)=(Uc-Lc)+1
11