1 vote
1.5k views

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
0
it should be 1247
0
you too getting 1247?

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?
0
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 :(
2
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.
0
in general, let count the no.of elements stored before your required element stored in the memory.

no.of elements * size of element

but you have to take care with which no. starts the index
0
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
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.

## Related questions

1
11.8k 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 __________.