in DS
2,918 views
1 vote
1 vote

Consider array A[1..100,1..100],in which elements are stored in Z representation. An example of 5x5 such array is shown below: 

Base address of array = 1000,size of each element is 1 Byte,and stored in row major, then address of A[100][50] ?

in DS
by
2.9k views

2 Comments

it should be 1247
0
0
you too getting 1247?
0
0

1 Answer

3 votes
3 votes
As per the question, RMO is used

therefore the matrix will look like

A[1][1]  A[1][2] ....................................  A[1][100]

                                                             A[2][99]

                                                       A[3][98]

                                             .

                                    .     

                              .

          A[98][3]

      A[99][2]

A[100][1]   A[100][2] ...............................A[100][100]

We want to go to element A[100][50]

means we need Row=100 and column=50

row1 has all 100 elements

row2 to 98 have 1 element only

row 100 has all 100 elements

therefore RMO = base + cross row1 + cross elements of row 2 to 98 + cross 49 elements in row 100 to reach 50th element

                          =  1000 + 100 + 98 + 49

                         =  1247Bytes?

5 Comments

Here, this was a new question for me. Suppose in GATE they asked totally a new question like this with any other representation like lower triangular,Upper or here its Z shape. Can you explain in general how to lookup the problem at get the address. I sometimes get confuse :(
0
0
edited by
You have to observe the pattern carefully. Actually this question is a lot easier than it seems. Only the first and last row has n elements, rest have only one element. Remember, questions can be new, but if they are present in GATE, they are very much solvable within the time limit if you catch the point of the question, and practice alot.
2
2
in general, let count the no.of elements stored before your required element stored in the memory.

no.of elements * size of element

Add Base address

but you have to take care with which no. starts the index
0
0
edited by
Yeah
don't think from prospective of formula
for example shape is T
then, the elements will be
 A[1][1]  A[1][2].............................A[1][100]
                                A[2][50]
                                  .
                                 .
 
                                A[100][50]

here you know if u want to reach A[1][1] you need not cross any element, therefore, RMO = base =1000
for A[1][2] = 1000+1
for A[2][5] this kinda arrangement won't exist.
for A[100][50]  = 1000 + cross row 1(100 elements) + 1element in all 98rows
0
0
It should start from A[2][50] and the calculation should be 1000 + 100 + 99 (99 because 1st row is already crossed andfrom 2nd row only 1 element. In 100th element we will get 50th column) please correct me if I'm wrong.
0
0

Related questions

2 votes
2 votes
1 answer
2