# Multidimensional Arrays in Java

For a multidimensional array, the element with indices i,j would have address B + c Â· i + d Â· j, where the coefficients c and d are the row and column address increments, respectively.

More generally, in a k-dimensional array, the address of an element with indices i1, i2, ..., ik is

B + c1 Â· i1 + c2 Â· i2 + ... + ck Â· ik. For example: int a;

This means that array a has 2 rows and 3 columns, and the array is of integer type. Here we can store 6 elements they are stored linearly but starting from first row linear then continuing with second row. The above array will be stored as a11, a12, a13, a21, a22, a23.

This formula requires only k multiplications and k additions, for any array that can fit in memory. Moreover, if any coefficient is a fixed power of 2, the multiplication can be replaced by bit shifting.

The coefficients ck must be chosen so that every valid index tuple maps to the address of a distinct element.

If the minimum legal value for every index is 0, then B is the address of the element whose indices are all zero. As in the one-dimensional case, the element indices may be changed by changing the base address B. Thus, if a two-dimensional array has rows and columns indexed from 1 to 10 and 1 to 20, respectively, then replacing B by B + c1 - âˆ’ 3 c1 will cause them to be renumbered from 0 through 9 and 4 through 23, respectively. Taking advantage of this feature, some languages (like FORTRAN 77) specify that array indices begin at 1, as in mathematical tradition while other languages (like Fortran 90, Pascal and Algol) let the user choose the minimum value for each index.

References : Wikipedia share on :        :

Love to hear your Views / Guidance / Recommendations on this Post…

Explore the Technology World

Call / Visit for New Batch

Services

• ➯ Free Demo Classes
• ➯ No Registration Fee
• ➯ Interview Questions
• ➯ Study Materials
• ➯ Softwares
• ➯ Aptitude & Reasoning
• ➯ Placement Assitance