in Programming
4,298 views
3 votes
3 votes
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 ________. (Assume the first element is stored at A[1][1][1] and each element take 1 memory location)
in Programming
by
4.3k views

4 Comments

can u explain what you did for CMO ?

Base Add + (k-1)r1r2 + (j-1)r2 + (i-1).....??
0
0
can u please explain how to count in case of 3D ??
0
0
For RMO:10+19*30*40+19*40+29

for CMO 10+19*30*40+29*30+19
4
4
This is correct answer.

Please explain how did u solve ?
0
0

2 Answers

3 votes
3 votes

For Row Major Order Derivation :-

3 Comments

@Shaik Masthan

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

https://gateoverflow.in/29361/find-address-of-element-in-3d-array

For this question it should for CMO:

 [ (5-2)[(8-2+1)*(10-2+1)] + (5-2)*(8-2+1) + (5-2) ] * size + BA

3*7*9 + 3*7 + 3 + 500 ===> 713

What is wrong in this ? in answer it is 624

first [2...6] will shows that 5 2D array with each 2 array of size [7][9] right ?

0
0

@Shaik Masthan how will we take for the column major ??

0
0
0 votes
0 votes

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} (k=1...d)$, a given element of this array is specified by a tuple $(n_1, n_2, \ldots, n_d)$ of d (zero-based) indices $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

Related questions