Sunday, October 11, 2009

ADDRESS CALCULATION OF ARRAY ELEMENT A [J][K]

The computer keeps track of Base (A), the address of the first element

A[0][0] of A[M][N], and computes address Loc (A[J][K]) of A[M][N] using the formula

Column–Major Order:

Loc (A[J][K] ) = Base (A) + W [M x K + J ]

OR

ROW MAJOR ORDER:

Loc (A [J][K]) = Base (A) + W [N x J + K ]

W denotes the size, i.e; number of bytes per data element of the array A, M is total numbers of rows, and N is total number of columns in the array.

4 comments:

  1. Row Major Order:-
    Base Address + Element Size[no. of column(i-lower bound of row)+(j-lower bound of column)]

    Column Major Order:-
    Base Address + Element Size[no. of row(j-lower bound of column)+(i-lower bound of row)]

    ReplyDelete
    Replies
    1. The above formula is for INDIAN Schools.Smarter Formula is the one posted- the formula internationally accepted and accepted by java certificaters.

      Delete
  2. http://www.javaforschool.com/625348-memory-address-calculation-in-an-array/

    ReplyDelete