reshown by
15,758 views
5 votes
5 votes

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].

reshown by

6 Answers

Best answer
12 votes
12 votes
Since it is stored in Column Major Order, hence:

= 10 + (19*30*40) + (29*30) + 19

= 23699
selected by
7 votes
7 votes
To solve these kind of problems, please do not use any kind of formulas, we just need to understand how 3D arrays will store thats it solution is over.

Now see given question A[90][30][40], which means total there are 90, 2D  arrays were present and size of each 2D array is 30*40 (which is 1200 elements)

However the array is 2D,3D,4D.....nD  it will store it  as 1D array only in the memory

It is important to see whether the array is stored in RMO or CMO.

as per the given question it is stored ad CMO.

 

address of an element = BA + (number of elements to cross to reach that element) * size of each element

So lets see to reach A[20][20][30], we need to see how many elements  to cross

1) 19 -2D array elements = 19*30*40 = 19*1200

2)now we are at 20th 2D array, here we need to see RMO or CMO

CMO:-

2.1)column elements cross = 29 columns = 29 × 30  (because each column contains 30 elements)

2.2)now to reach  20th 2D element (20,30) we need to cross some more elements in 30th column = 19 elements

So total ( 19×30×40) + (29×30) +  19 = 23689 elements to cross, it  is given that each element size is 1B, and BA is 10 so final anser is 10 + 23689 = 23699

 

RMO:-

3.1)row elements cross = 19 rows = 19×40 (because each row  contains 40 elements)

3.2)now to reach 20th 2D element (20,30) we need to cross some more elements in 20th row = 29 elements

So total (19×30×40) + (19×40) + 29 =  23589 elements

So answer is 23589 +10 = 23599

 

PLEASE  DONT USE ANY FORMULA
3 votes
3 votes
Assume that the size of the matrxi is A[m][n]

The address of the location A[i][j]can be find by using this formula in case of column major order

BA+(j*n+i)size of each element (if index starts from zero)

BA+((j-1*)n+i-1) *size of each element (if index starts from one)

if the array is contains rows also then formula will be

BA+(rows-1)*m*n+BA+(j*n+i)size of each element (if index starts from zero)

BA+(rows-1)*m*n+((j-1*)n+i-1) *size of each element (if index starts from one)

Now the answer for the above question is

10+19*30*40+29*30+19=23699

Related questions

0 votes
0 votes
1 answer
1
viral8702 asked Apr 29, 2022
447 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)?...
16 votes
16 votes
3 answers
2
shikharV asked Dec 4, 2015
15,478 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 __________...
3 votes
3 votes
2 answers
3
Anjan asked Jan 8, 2018
6,283 views
Consider 3 dimensional Array A[90] [30] [40] stored in linear array. If the base address starts at 10, The location of A [20] [20] [30] in case of RMO and CMO are _______...
3 votes
3 votes
1 answer
4
KISHALAY DAS asked Dec 11, 2016
1,354 views