Skip to content

ISRO Scientist/Engineer CSE 2017Data Structures › Not yet assigned to a topic

ISRO Scientist/Engineer CSE 2017 PYQ: In a compact one-dimensional array representation for lower triangular matrix (all elements above diagonal…

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. A
    $i+j$
  2. B
    $j+\dfrac{i(i-1)}{2}$
    Correct answer
  3. C
    $i+j-1$
  4. D
    $i+\dfrac{j(j-1)}{2}$

Answer

(B) $j+\dfrac{i(i-1)}{2}$

Approach

For a lower triangular matrix stored row-by-row, the number of elements before row i is the sum of the first (i-1) row lengths: 1 + 2 + ... + (i-1) = i(i-1)/2. Within row i, the element in column j is the j-th element (assuming 1-based indexing). Thus the 1-based index is j + i(i-1)/2.

Reviewed by ISRO IQ Editorial Team.