Row and column Major Ordering in an array

Let us see Row and column Major Ordering in an array one by one below.

Recommended Book: Data Structures and algorithms

Row Major Ordering in an array:-

Row major ordering assigns successive elements, moving across the rows and then down the columns, to successive memory locations.

In simple language, if the elements of an array are being stored in Row-Wise fashion. This mapping is demonstrated in the below figure:

The formula to compute the Address (offset) for a two-dimension row-major ordered array as:

Row and column Major Ordering in an array
Row and column Major Ordering in an array

Address of A[I][J] = Base Address + W * ( C * I + j)

Where Base Address is the address of the first element in an array.

  • W= is the weight (size) of a data type.
  • C= is Total No of Columns.
  • I= is the Row Number
  • J= is Column Number of an element whose address is to find out.

Column Major Ordering

If the element of an array is being stored in Column Wise fashion then it is called column-major ordering in an array. In row-major ordering, the rightmost index increased the fastest as you moved through consecutive memory locations. In column-major ordering, the leftmost index increases the fastest.

Pictorially, a column-major ordered array is organized as shown below

Row and column Major Ordering in an array

The formulae for computing the address of an array element when using column-major ordering is very similar to that for row-major ordering. You simply reverse the indexes and sizes in the computation:

For a two-dimensional column-major array:

Address of A[I][J] = Base Address + W * ( R * J + I)

Where Base Address is the address of the first element in an array.

  • W= is the weight (size) of a data type.
  • R= is Total No of Rows.
  • I= is the Row Number
  • J= is Column Number of an element whose address is to find out.

Address Calculation in single-dimensional Array: In 1-D array, there is no Row Major and no Column major concept, all the elements are stored in contiguous memory locations. We can calculate the address of the 1-D array by using the following formula:

Address of A[I] = Base Address + W * I.

Where I[ is a location(Indexing) of element] whose address is to be found out. W (is the size of data type).

Recommended post: