Column Major Order Representation of Array


Column Major Order is a method of representing multi dimension array in sequential memory.
In this method elements of an array are arranged sequentially column by column. Thus elements of first column occupies first set of memory locations reserved for the array, elements of second column occupies the next set of memory and so on.
Consider a Two Dimensional Array consist of N rows and M columns. It can be stored sequentially in memory column by column as shown below:

Column 0 A[0,0] A[1,0]   A[N-1,0]
Column 1 A[0,1] A[1,1]   A[N-1,1]
   
Column N-1 A[0,M-1] A[1,M-1]   A[N-1,M-1]
     

Example:
Consider following example in which a two dimensional array consist of two rows and four columns is stored sequentially in Column Major Order as:

2000
A[0][0]
Column 0
2002
A[1][0]
2004
A[0][1]
Column 1
2006
A[1][1]
2008
A[0][2]
Column 2
2010
A[1][2]
2012
A[0][3]
Column 3
2014
A[1][3]

 

The Location of element A[i, j] can be obtained by evaluating expression:
LOC (A [i, j]) = Base_Address + W [N (j) + (i)]
Here,
Base_Address
is the address of first element in the array.
W is the word size. It means number of bytes occupied by each element.
N is number of rows in array.
M is number of columns in array.
Suppose we want to calculate the address of element A [1, 2].
It can be calculated as follow:
Here,
Base_Address = 2000, W= 2, M=4, N=2, i=1, j=2

LOC (A [i, j]) = Base_Address + W [N (j) + (i)]
LOC (A[1, 2]) = 2000 + 2 *[2*(2) + 1]
  = 2000 + 2 * [4 + 1]
  = 2000 + 2 * 5
  = 2000 + 10
  = 2010

Download Projects


Download Programs