Column Major Order in Data Structure with Example

Column Major Order is a way to represent the multidimensional array in sequential memory. It has similar functionality as row-major order, but the way of process is different.

In Column Major Order, elements of a multidimensional array are arranged sequentially column-wise which means filling all the index of the first column and then move to the next column.

Let’s see an example

Suppose we have some elements {1,2,3,4,5,6,7,8} which we want to insert in an array by following column-major order.

So If we insert these elements in column-major order, our 2-D array will look like

Here first fill index[0][0] and then index[1][0] which is just opposite to the row-major where we first fill all row nodes then move to the next row.
And then for second-column index[0][1] and then index[1][1], index[0][2], index[1][2] and so on.

Column Major Order Formula

The Location of element A[i, j] can be obtained by evaluating expression:

LOC (A [i, j]) = base_address + W [N (j) + (i)]


base_address = address of the first element in the array.

W = Word size means a number of bytes occupied by each element of an Array.

N = Number of rows in the array.

M = Number of columns in the array.

Here we have taken a 2-D array A [2, 4] which has 2 rows and 4 columns.

Now to calculate the base address of any index using column major order we can use process given below.

It can be calculated as follow:
base_address = 2000, W= 2, N=2, M=4, i=2, j=3
LOC (A [i, j]) = base_address + W [M (j) + (i)]
LOC (A[2, 3]) = 2000 + 2 [4(3) + 2]
= 2000 + 2 * [12 + 2]
= 2000 + 2 * 14
= 2000 + 28
= 2028

Share on