Log In
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 1.5k views
it should be 1247
you too getting 1247?

1 Answer

2 votes
As per the question, RMO is used

therefore the matrix will look like

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








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?
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 :(
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.
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
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]

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

16 votes
3 answers
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 __________.
asked Dec 4, 2015 in DS shikharV 11.8k views
4 votes
1 answer
Please solve the above problem. Given answer: D
asked Nov 16, 2015 in DS shikharV 1.3k views
1 vote
1 answer
Let's say we have an array of 5 elements. Array index starts from 0 Base address of Array = 100 size of each element is 2 ie it's an int array Now we want to find the 2nd element ie A[2]. So, the procedure is like - A[2] = Base address + (index*size of each element in memory) A[2] = 100+(2*2) Now how to find the BOLD text ie address of 2nd element in BINARY?! Thanks
asked Apr 28, 2017 in Programming iarnav 1.2k views
3 votes
3 answers
I am not getting the answer , (11*8*13+67)*4+ base address =400+4844= 5244. But the answer is 5336, please explain. similar question is here:
asked Dec 12, 2016 in Programming vishwa ratna 1.2k views