edited by
15,586 views
16 votes
16 votes
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 __________.
edited by

3 Answers

Best answer
22 votes
22 votes

A[x][y][z] = A[6-2+1][8-2+1][10-2+1]. So A[5][7][9] is our 3-D array.

It contains 2-D arrays (comprises of 5 rows and 7 columns) arranged in 9 layers making it a 3-D array.

In total we have 5 rows({2,3,4,5,6}) in the similar way we have 7 columns({2,3,4,5,6,7,8}) and 9 layers({2,3,4,5,6,7,8,9,10}).

So in the layer 1 ({2,3,4,5,6,7,8,9,10}) we have  7 Columns * 5 Rows = 35 Elements. In the similar way each of the remaining layers also contain 35 elements.

Here we have to use column major Order to find the address of A[5][5][5]. Base Address is 500.

Here the index of z is 5. so we can have the required element in the 4 th layer({2,3,4,5,6,7,8,9,10}). Upto 3 layers({2,3,4,5,6,7,8,9,10}) we will have (3 layers *35 elements) 105 elements.

Now in the 4th layer we can find the number in 4th column({2,3,4,5,6,7,8}) in 4th row({2,3,4,5,6}). As we have to look in column major order upto 3rd column ({2,3,4,5,6,7,8}) we will have (3 columns * 5 rows) 15 elements.

Then in the  4th column upto 4 rows we have 3 elements.

Let us consider the size of each element is of 1 Byte.

So the address of the element in the location A[5][5][5] is Base Address + (Total Number of elements ) * Size of each element (We add one to get to the current element)

LOCATION(A[5][5][5]) = 500 + (105 + 15 + 3 )*1 = 623.

selected by
1 votes
1 votes
I considered the above as 9*(7x5) 2D arrays in that case to reach A[5], we need to cross 4*(7x5) 2D arrays ie. 140.

After that add 4*7 iterations + 4 to reach A[5][5] , this makes it- 28+4=32

So adding to the base address I got 500+172=672.

Related questions

2 votes
2 votes
1 answer
2
shikharV asked Nov 16, 2015
2,349 views
Please solve the above problem. Given answer: D
3 votes
3 votes
3 answers
3
vishwa ratna asked Dec 12, 2016
2,622 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: https://gateoverflow.in/29361/...
5 votes
5 votes
6 answers
4
Pankaj Joshi asked Jan 26, 2017
15,843 views
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 __________...