GATE CSE
First time here? Checkout the FAQ!
x
+2 votes
183 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)   | 183 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 (47k 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.1k points)   | 40 views
+1 vote
0 answers
2
asked in DS by pC Veteran (20.3k points)   | 186 views
0 votes
3 answers
3
asked in Programming by iarnav Active (1.2k points)   | 153 views


Top Users May 2017
  1. akash.dinkar12

    3338 Points

  2. pawan kumarln

    2108 Points

  3. Bikram

    1922 Points

  4. sh!va

    1682 Points

  5. Arjun

    1614 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1208 Points

  8. Angkit

    1056 Points

  9. LeenSharma

    1018 Points

  10. Arnab Bhadra

    812 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    1008 Points

  2. pawan kumarln

    734 Points

  3. Arnab Bhadra

    726 Points

  4. Arjun

    342 Points

  5. bharti

    328 Points


22,893 questions
29,196 answers
65,302 comments
27,695 users