How to find address using Column Major Order?
Given an array arr[1………10][1………15] with a base value of 100 and the size of each element is 1 Byte in memory find the address of arr[8][6] with the help of column-major order.
Solution:
Given:
Base address B = 100
Storage size of one element store in any array W = 1 Bytes
Row Subset of an element whose address to be found I = 8
Column Subset of an element whose address to be found J = 6
Lower Limit of row/start row index of matrix LR = 1
Lower Limit of column/start column index of matrix = 1
Number of Rows given in the matrix M = Upper Bound – Lower Bound + 1
= 10 – 1 + 1
= 10Formula: used
Address of A[I][J] = B + W * ((J – LC) * M + (I – LR))
Address of A[8][6] = 100 + 1 * ((6 – 1) * 10 + (8 – 1))
= 100 + 1 * ((5) * 10 + (7))
= 100 + 1 * (57)
Address of A[I][J] = 157
From the above examples, it can be observed that for the same position two different address locations are obtained that’s because in row-major order movement is done across the rows and then down to the next row, and in column-major order, first move down to the first column and then next column. So both the answers are right.
Row Major Order and Column Major Order
When it comes to organizing and accessing elements in a multi-dimensional array, two prevalent methods are Row Major Order and Column Major Order. These approaches define how elements are stored in memory and impact the efficiency of data access in computing.
Table of Content
- Row Major Order
- How to find address using Row Major Order?
- Column Major Order
- How to find address using Column Major Order?
- Row Major Order vs Column Major Order
Let us discuss them in detail one by one.