edited by
595 views
2 votes
2 votes

A $2$-dimentional array is declared as  $A[-8 \text{ to } 12, \ -4 \text{ to } 16]$ , what will be the address of $A[1,3]$ if it is stored in row major order , each element occupies $4$ bytes and starting address of array is $2000$.

  1. $2784$
  2. $2776$
  3. $2794$
  4. $2764$
edited by

3 Answers

Best answer
2 votes
2 votes
Original matrix = A[lb1...ub1 , lb2..ub2]

n = size of column (ub2-lb2+1)

find address for A[i][j]

then for row major order,

[(i-lb1)*n + (j-lb2)]* size of each element +Base Address

thus A[1,3] = [(1+8)*21 + (3+4)]*4 +2000 = 784+2000 = 2784
selected by
0 votes
0 votes

Normally, to access $A[1][3]$ we skip 1 rows and 3 columns. Because we assume the first element to be $A[0][0]$

 

But here, since the first element is at $A[-8][-4]$, to reach $A[1][3]$ skip 9 rows and 7 columns.

=> Skip 9 rows + 7 elements

=> Skip 9*(column length) elements + 7 elements

=> Skip 9(21) elements + 7 elements

=> Skip 189 elements + 7 elements

=> Skip 196 elements

=> Skip 196 * 4 bytes

=> Skip 784 bytes from the base address 2000.

=> 2784

 

Option A

Answer:

Related questions

0 votes
0 votes
1 answer
2
Bikram asked Nov 26, 2016
1,637 views
Three algorithms do the same task. Algorithm One is $O(N)$ and Algorithm Two is $O(\log N)$ and Algorithm Three is $O(N1/2)$. Which algorithm should execute the fastest f...
1 votes
1 votes
3 answers
3
0 votes
0 votes
0 answers
4