The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+3 votes
231 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 (8.7k points) | 231 views
I am getting answer as 130700 but answer given is 127700. So am I correct or wrong ? If wrong then plz tell how u solved.
a[-25....+ 25,-25....+ 25,] means a[51][51] (or) something else ?
yes getting 130700 only
as it is a upper triangular matrix u need not store the zero's...so it is just like accessing the array[45][47]....we can assume the array as array[50][50],....so the 51st element in first row will have address of 5000....now second row will have one zero  no need to store we will get the last element address by adding 4900 to it...so on proceeding like this uptil array[44][50]...the lasst element will be given by adding (5000-4400=600)...so adding these all we get 5000+4900+...+600.=126000...but we want a[45][47] so in the 45th row u have 46 zeros so u need to add 200 to it 126000+200=126200... iam getting this 126200
@mcjoshi and @Pavan the array is a[51][51] .
there are 51 items so it should a[50] right?
oh yeah sorry it should be a[50][50]
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

+11 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 (57.4k points)
edited by
Nice explanation :)
@Debashish, We can use this as a formula, right ?

Otherwise, i always calculated it manually.
yes this is valid.
@Debashish Can you give formula for lower triangle matrix also rmo and cmo both.


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

28,834 questions
36,689 answers
90,626 comments
34,641 users