760 views
1 votes
1 votes
A 30*30  upper triangular matrix of integers is stored optimally in a 1-D array with starting address of 3000 assume the matrix indexing starts at (1,1) and array indexing starts at 0 what would be the address of element with index (25,25)), assume one integer takes up two bytes of memory.___

Need help in this one. Didn’t get the solution properly provided by them. Anyone!

1 Answer

Best answer
3 votes
3 votes

Since the matrix is upper triangular matrix number of elements in :

1st row = 30

2nd row = 29

.

.

.

24th row = 30 – (n-1) = 30 – 23 = 7

Since till 24th row we have to consider all the elements.

∴ Total #elements = 30 + 29 + 28 + … + 7  (which is in AP)

= $\frac{n}{2}(2*a + (n-1)*d  =  \frac{24}{2}(2*30 + (24-1)*-1)$

= $444$

Now since matrix is upper triangular matrix index (25, 25) will correspond to 1st element of the 25th row.

∴ Address of (25, 25) = 3000 + (number of elements)* size of each element

 = 3000 + 444*2 = 3000+888 = 3888

Answer: 3888

selected by

Related questions

0 votes
0 votes
0 answers
1
Vishal Goyal asked Dec 6, 2016
293 views
2 votes
2 votes
2 answers
2
LRU asked Oct 15, 2021
650 views
Consider an array contains n integers, each integer belongs to {0, 1, 2}. What is the best case time complexity to sort an array?