How to find address using Row Major Order?
Given an array, arr[1………10][1………15] with base value 100 and the size of each element is 1 Byte in memory. Find the address of arr[8][6] with the help of row-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 column given in the matrix N = Upper Bound – Lower Bound + 1
= 15 – 1 + 1
= 15Formula:
Address of A[I][J] = B + W * ((I – LR) * N + (J – LC))Solution:
Address of A[8][6] = 100 + 1 * ((8 – 1) * 15 + (6 – 1))
= 100 + 1 * ((7) * 15 + (5))
= 100 + 1 * (110)
Address of A[I][J] = 210
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.