GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
175 views
a[-25.....+25, -25......+25], Base address=0 and size of element = 100 bytes

Find the location of a[20][22] ?

Also Matrix is upper triangular matrix with row major order
asked in Programming by Boss (7.7k points)   | 175 views
number of elements we shud cross before accessing a[20][22] is 1307. 1308th element is a[20][22]
51+50+49+48....7 these are the elements till 19th row. now in 20th row we will have to cross 2 elements.
so total elements to cross= 51+50...+7+2 =1307. index of a[20][22] = 1307.
0th element address--->0
1st element address--->100
2nd--->200
>
>
100th element address= 10000
>
1307th element address= 130700
by a[x][y] we mean there are 'x' 1D arrays of size 'y' isnt it? why is it a[50][50]
I applied same method @Anusha. So I think 130700 is correct
Array stores 51 elements. So, it should be a[51][51], index varies from 0 to 50
not abel to get 1307!!!!!
summation of 51 to 33 ie 19th term of the sequence is 798. kindly help in calculating
not able to get the calculation of the elements of first 19 rows

1 Answer

+8 votes
Best answer

$130700$ is correct !

  • $ub_1$ = upper bound index on rows
  • $ub_2$ = upper bound index on columns

$\begin{align*} &\Rightarrow \text{LOC}\left ( a[X][Y] \right ) = \text{BA} + \left ( \frac{\text{n}\_\text{row}(\text{n}\_\text{row}+1)}{2} - \frac{(\text{ub}_1 - X +1)(\text{ub}_1 - X +2)}{2} + Y-X \right )*E \\ & \Rightarrow \text{LOC}\left ( a[X][Y] \right ) = 0 + \left ( \frac{51*52}{2} - \frac{6*7}{2} + 2 \right )*100 \\ & \Rightarrow \text{LOC}\left ( a[X][Y] \right ) = 130700 \\ \end{align*}$

answered by Veteran (43.9k points)  
edited by
Nice explanation :)
@Debashish, We can use this as a formula, right ?

Otherwise, i always calculated it manually.
yes this is valid.

Related questions

0 votes
0 answers
1
asked in DS by Vishal Goyal Junior (899 points)   | 38 views
+1 vote
0 answers
2
asked in DS by pC Veteran (20.2k points)   | 168 views
0 votes
1 answer
3
asked in Programming by shu (151 points)   | 58 views


Top Users Mar 2017
  1. rude

    5236 Points

  2. sh!va

    3054 Points

  3. Rahul Jain25

    2920 Points

  4. Kapil

    2732 Points

  5. Debashish Deka

    2602 Points

  6. 2018

    1574 Points

  7. Vignesh Sekar

    1430 Points

  8. Bikram

    1424 Points

  9. Akriti sood

    1420 Points

  10. Sanjay Sharma

    1128 Points

Monthly Topper: Rs. 500 gift card

21,549 questions
26,889 answers
61,247 comments
23,251 users