recategorized by
1,829 views
9 votes
9 votes

In a compact one-dimensional array representation for lower triangular matrix (all elements
above diagonal are zero) of size $n\times n,$ non zero elements of each row are stored one
after another, starting from first row, the index of $(i,j)^{th}$ element in this niw representation is

  1. $i+j$
     
  2. $j+\dfrac{i(i-1)}{2}$
     
  3. $i+j-1$
     
  4. $i+\dfrac{j(j-1)}{2}$
recategorized by

1 Answer

11 votes
11 votes

NB: Question is ambiguous ,Nothing specified in question whether matrix index starts from (0,0) or (1,1).

Quick way to solve such questions in exams will be checking options with an example.!

$\begin{bmatrix} 1 &0 &0 \\ 2 & 3 & 0\\ 4 & 5& 6 \end{bmatrix}$

can be compactly written in an array as

$\begin{bmatrix} 1 &2 &3 &4 &5 & 6 \end{bmatrix}$

Trial 1:

  • let us assume index starts as (0,0)
  • For element 5, index will be (i,j)= (2,1) and stored in array index 4
  • No option gives 4 as answer

Trial 2:

  • Assume matrix index starts as  (1,1)
  • Again check element 5, index will be (i,j)= (3,2) and stored in array index 5. Only options A and B give result as 5. Eliminate C and D 
  • Now check element 1, index will be (i,j)= (1,1) and stored in array index 1. only option B will give result as 1.

Answer is B

Answer:

Related questions

9 votes
9 votes
2 answers
1
gatecse asked Dec 17, 2017
3,755 views
Consider the following $C$ function#include<stdio.h int main(void) { char c[]="ICRBCSIT17" char *p=c; printf("%s",c+2[p]-6[p]-1); return 0; }The output of the program is ...
3 votes
3 votes
2 answers
2
gatecse asked Dec 17, 2017
1,675 views
Consider the functionint func(int num) { int count=0; while(num) { count++; num>>=1; } return(count); }For $func(435)$ the value returned is$9$$8$$0$$10$
2 votes
2 votes
1 answer
3
gatecse asked Dec 17, 2017
2,145 views
Consider the functionint fun(x: integer) { If x>100 then fun=x-10; else fun=fun(fun(x+11)); }For the input $x=95$, the function will return$89$$90$$91$$92$
5 votes
5 votes
1 answer
4
gatecse asked Dec 17, 2017
1,456 views
Which one of the following are essential features of object-oriented language? A.Abstraction and encapsulation B.Strictly-typed C.Type-safe property coupled with sub-type...