2,559 views
3 votes
3 votes

I am not getting the answer , (11*8*13+67)*4+ base address =400+4844= 5244.

But the answer is 5336, please explain.

similar question is here: https://gateoverflow.in/29361/find-address-of-element-in-3d-array

3 Answers

5 votes
5 votes

[Correct me if wrong... Im getting 5240 ]

Let D 3D Array be represented as $A\left [ lb1....ub1,lb2....ub2,lb3...ub3 \right ]$
Given Array : $A\left [ 1....8,-5....5,-10...5 \right ]$ 
 3D array is  $A\left [ 8,11,16 \right ]$ . 

A[i,j,k] = Base Address
             + [ 3D Cross
              + 2D Cross
               +  1D Cross ] * Size of one element
3D Cross
 $ (k-lb3) = 3- (-10) =13$ layers are to be crossed
Each layer having row * coloum  number of elements
 Total number of elements to be crossed = 13 * 8*11 = 1144

2D Cross
 $ (j-lb2) = 3- (-5) =8$ coloums are to be crossed
Each column having  " row "    number of elements
 Total number of elements to be crossed = 8*8 = 64

1D Cross
We are reached last coloumn . It will have
$ (i-lb1) = 3- (1) =2$ elements  to be crossed

Hence
 A [3,3,3] = 400
                 [+ 1144
                   + 64
                     + 2  ] * 4
                 = 400 + 4840
                  =5240

0 votes
0 votes

Since its column major and 3-d array.

1st index will show M and 2nd index will show N where,

M = No. of Rows = U1 - L1 + 1 = 8-1+1 = 8

N = No. of Columns = U2 - L2 + 1 = 5-(-5)+1 = 11

A[3][3][3] = Base + Size ( (i-L1) * M*N + (j-L2) + (k-L3)*M )

                = 400 + 4 ( (3-1)* 8 *11   +  (3-(-5))    + (3-(-10)* 8 ) )

                = 400 + 4 ( 176 + 8 + 104 )

                = 1552 

[Note that in row major 1st index shows array, 2nd shows rows and 3rd columns]

practice it with taking any small 3d array by yourself.

edited by
0 votes
0 votes
Cm=BA+w[(E3L2+E2)L1+E1)

Li=Ub-Lb+1

Let A[3][3][3]= A[i][j][k]

E1=i-lb     E2=j-lb   E3=k-lb

From formula we get

L1=8-1+1=8                  E1=3-1=2

L2=5-(-5)+1                   E2=3-(-5)=8

L3=5-(-10)+1                  E3=3-(-10)=13

=400+4[(13*11+8)8+2]

=400+4[1210]

=5240

Related questions

16 votes
16 votes
3 answers
2
shikharV asked Dec 4, 2015
15,477 views
A is an array $[2.....6, 2.....8, 2.......10]$ of elements. The starting location is $500$. The location of an element $A(5, 5, 5)$ using column major order is __________...
2 votes
2 votes
1 answer
3
shikharV asked Nov 16, 2015
2,319 views
Please solve the above problem. Given answer: D
0 votes
0 votes
1 answer
4
viral8702 asked Apr 29, 2022
446 views
A frame buffer array is addressed in row major order for a monitor with pixel locations starting from (0,0) and ending with (100,100). What is address of the pixel(6,10)?...