Addressing formula of (i,j)th element of a m*n matrix in column-major order.

In this article we will learn how to calculate address of (i,j)th element of a matrix m*n in Column major order. Below is the explanation of it.

Column Major Order Formula

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

LOC (A [i, j]) = base_address + W [M (j-1) + (i-1)]

Here,

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.

M = Number of rows in the array.

N = 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:
Here,
base_address = 2000, W= 2, M=2, N=4, i=2, j=3
LOC (A [i, j]) = base_address + W [M (j-1) + (i-1)]
LOC (A[2, 3]) = 2000 + 2 [2(2) + 1]
= 2000 + 2 * [4 + 1]
= 2000 + 2 * 5
= 2000 + 10
= 2010