Question 74Asked in DSSSB PGT Computer Science (Technical), 11 Jul 2021

Consider a n × n tri-diagonal sparse matrix A. Suppose we want to store sparse A in a one-dimensional array. What is the index of the (i,j)th element of A…

Consider a n × n tri-diagonal sparse matrix A. Suppose we want to store sparse A in a one-dimensional array. What is the index of the (i,j)th element of A in the one-dimensional array?
  1. A2i + 2j
  2. B2i + j − 2
  3. Ci + j
  4. Di + j − 1
Show answerHide answer

Correct answer: (B) 2i + j − 2

Explanation

Row-major with 1-based indexes, rows before row i hold 3(i−1) − 1 elements, and (i, j) is the (j − i + 2)th element of row i. Total = 3i − 4 + j − i + 2 = 2i + j − 2.

From DSSSB PGT Computer Science PYQ (Technical), 11 Jul 2021

This is question 74 of DSSSB PGT Computer Science PYQ (Technical), 11 Jul 2021. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.