GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
328 views

 

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: http://gateoverflow.in/29361/find-address-of-element-in-3d-array

asked in Programming by Active (2.5k points) 2 17 46 | 328 views
yes ,u r approach is correct.
what i am missing?
your answer is also correct.options are given wrong

@santhoshdevulapally  SIR  can u pls explain your approch in detail as answer to this question .?
Im getting 4840 :(

2 Answers

+1 vote

[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

answered by Veteran (22.8k points) 46 216 358

in the 1-d array access the 3rd element because it is the last row to access,no need to cross that element.

1-d array elements are ${\color{Red} 1,2,3},4,5,6,7,8$.so access until 3rd element.

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

 

You need to access the third element also, the third element will give the required address, so the answer should be: 5244.

Still the answer the solution key is different , the thing to worry is that they too have some shitty explaination for it :P

@vishwa,5244 is correct answer.

@santhoshdevulapally  can u pls once again check ?  I'm still getting 5240

3rd Element will have base address 5240

A[1][3][3]=5236.

A[1,2,3( row)...8,-5(coloumn),...5,-10,...5(layers)]

i think last row u can access before the element but not the actual element,that is why u have different answer.

400+((3*11*8)+8*8+1)*4

=5236.

@santhoshdevulapally ,
400+((3*11*8)+8*8+1)*4   What is the reason for  adding extra 1 here  ?
I think  you are referring from http://gateoverflow.in/29361/find-address-of-element-in-3d-array .  I think that there also need one correction .


For simplicity just consider the array A[10.....13][-3....-1]  Base address : 200 . Each lement takes 1 B .  If used CMO  then what will be the location of A[13][-3]  ?

CMO stored as

The 2d Array will be A[14-11 +1 ][-1-(-3)+1] ie A[4][3]
A[i,j] = Base Address
             + [  2D Cross
               +  1D Cross ] * Size of one element

A[13][-3] =  200

               + [ (-3-(-3)) * 2
                    +13-(11) ]
A[13][-3] = 200+ (0*2+2)*1 =202

Correct me if wrong... 

u r correct bro.Nice explanation .

i just consider given link problem.
can anybody provide me with a refrence that says in A[x,y,z] z is for plane and not x
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.

answered by Junior (725 points) 3 9
edited by

Related questions

+1 vote
1 answer
1
asked in Programming by iarnav Loyal (4.6k points) 4 39 112 | 206 views
+12 votes
2 answers
2
asked in DS by shikharV Boss (5.8k points) 25 107 177 | 4.3k views
+1 vote
1 answer
3
asked in DS by shikharV Boss (5.8k points) 25 107 177 | 488 views


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Top Users Oct 2017
  1. Arjun

    23338 Points

  2. Bikram

    17048 Points

  3. Habibkhan

    7912 Points

  4. srestha

    6228 Points

  5. Debashish Deka

    5438 Points

  6. jothee

    4968 Points

  7. Sachin Mittal 1

    4772 Points

  8. joshi_nitish

    4286 Points

  9. sushmita

    3964 Points

  10. Rishi yadav

    3794 Points


Recent Badges

Popular Question makhdoom ghaya
Popular Question junaid ahmad
Notable Question learner_geek
Notable Question jothee
Popular Question jothee
Notable Question Jeffrey Jose
Notable Question air1ankit
Nice Question jothee
Verified Human shaleen25
Popular Question jothee
27,290 questions
35,142 answers
83,920 comments
33,231 users