1,733 views
4 votes
4 votes
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

2 Answers

Best answer
13 votes
13 votes

$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*}$

edited by
1 votes
1 votes
$Changing\ question:$

$a[0...50,0...50]=a[51][51]$

$loc[45][47]:RMO$

$0^{th}\ row=51(0+x=51)$

$1^{st}\ row=50(1+x=51)$

$2^{nd}\ row=49(2+x=51)$

.

.

.

$44^{th}\ row=7(44+x=51)$

$Sum=51+50+49....+7=1305$

Now you are standing on $45^{th}$ row and it's first element will start from $45^{th}$ column but you need to go to $47^{th}$ column, hence add $3(45,46,47)$

$1305+3=1308$

But index starts from $0,$ so subtract $1$

$1308-1=1307$

$1307\times 100=130700$

Related questions

0 votes
0 votes
0 answers
1
rohit vishkarma asked Nov 6, 2017
302 views
0 votes
0 votes
0 answers
2
HeadShot asked Dec 1, 2018
191 views
Better than O(n) exists ?
0 votes
0 votes
0 answers
3
Vishal Goyal asked Dec 6, 2016
282 views
2 votes
2 votes
1 answer
4
pC asked Dec 23, 2015
974 views
There has to be a general method in deriving equations based on RMO and CMO .Could any one explain me how to derive formula of RMO and CMO of important matrices likeUpper...