GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
192 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.8k points)   | 192 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

+9 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 (50.5k 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 Active (1.9k points)   | 47 views
+1 vote
0 answers
2
asked in DS by pC Veteran (20.8k points)   | 222 views
+1 vote
1 answer
3
asked in Programming by Sourabh Kumar Active (1.9k points)   | 60 views


Top Users Jul 2017
  1. Bikram

    4386 Points

  2. manu00x

    2464 Points

  3. Debashish Deka

    1850 Points

  4. joshi_nitish

    1686 Points

  5. Arjun

    1340 Points

  6. Hemant Parihar

    1184 Points

  7. Arnab Bhadra

    1112 Points

  8. Shubhanshu

    1080 Points

  9. Ahwan

    900 Points

  10. rahul sharma 5

    732 Points


24,031 questions
30,983 answers
70,430 comments
29,358 users