in DS
745 views
3 votes
3 votes

Consider a two-dimensional array with elements stored in the form of lower triangular matrix. The elements must be crossed to read A[4, 2] from the array A[–6, ..., + 8, –6,..., + 8] whose base address 1000 is ________. (Assume elements are stored in row major order)

in DS
745 views

1 Answer

3 votes
3 votes

OR

If we take the size of each element as 1 bytes. 

Then its actually asking for the address of A[4][2] in the lower triangular matrix.

In Row Major Order, A[i][j] = Base + Size( (i - lower1) *NNS + (j-lower2) )     //NNS = Natural No.Sum.

So, A[4][2] 1000 + 1 ( ( 4-(-6) )*NNS + (2-(-6) ) )

                  = 1000 + (1+2+3+4+5+6+7+8+9+10) + 8

                  = 1000 + 55 + 8

                  = 1063

2 Comments

edited by
why do we use Natural No.Sum ?
0
0
why you use NSS why not ub2-lb2+1  i.e.1000+150+8?
1
1

Related questions