How to calculate 3-d address?

Consider 3 dimensional Array A[90] [30] [40] stored in linear array in column major order. If the base address starts at 10.

The location of A[20] [20] [30] is __________ . [Assume the first element is stored at A[1][1][1] and each element take 1 B]

how to calculate 3d address .

6Comments
Akshay Saxena @akshay0612
11 Aug 2017 08:29 pm

3 Dimnesional array is nothing but collection of 2 dimensional array * no of times . For example in this question : A is the collection of 20 arrays with rows 20 and columns 30. Calculate it that aspect since it is column major :
10+19*20*30+29*20+19

set2018 @setgate
12 Aug 2017 12:58 pm

not getting yet :(

see.arr[3][3][3] means we have 3 tables of 2d array which comprises of 3*3 (3 rows 3 columns ) i know the method to solve address for 2 d array but in this case m not geting :(

shivani @shivani1234
11 Aug 2017 10:01 pm

let us consider 3-d array[i,j,k] as modified form of 2-d array[i',j'] wher i' is a 2-d array[i,k]

now, we can can now solve easily by column major order of arr[m,n,p] :
= base address + (j-1)*size of element(n,p) + (i-1)*size of element(p) + k

= 10+ (20-1)*90*40 + (20-1)*40 + 30  = 69200

set2018 @setgate
13 Aug 2017 12:40 pm
set2018 @setgate
13 Aug 2017 12:41 pm

for this question i assume (A[1...90,1....30,1...........40])

and applying same technique 

but got 80039

Ashish Kumar Goyal @dashish
22 Aug 2018 04:15 pm

I guess we can refer this as a standard based on C(for Row-major) and Fortran(for Column major) compilers- 

 

Source:  https://en.wikipedia.org/wiki/Row-_and_column-major_order

 

"The concept generalizes to arrays with more than two dimensions.

 

For a d-dimensional \{\displaystyle N_{1}\times N_{2}\times \cdots \times N_{d}\} array with dimensions N(k=1...d), a given element of this array is specified by a tuple {\displaystyle (n_{1},n_{2},\ldots ,n_{d})} of d (zero-based) indices {\displaystyle n_{k}\in [0,N_{k}-1]}.

 

In row-major order, the last dimension is contiguous, so that the memory-offset of this element is given by:


In column-major order, the first dimension is contiguous, so that the memory-offset of this element is given by:

where the empty product is the multiplicative identity element, i.e.,    "

 

Referencehttps://en.wikipedia.org/wiki/Row-_and_column-major_order

Pages