GATE Computer ScienceHardGATE CS (PYQ pattern)

Only the non-zero band of a 20 x 20 tridiagonal matrix (entries with |i - j| <= 1, rows and columns numbered from 1) is stored in a 1-D array indexed from 1, once row by row and once column by column. At which indices does the element (12, 13) appear in the two layouts?

  1. A. 36 and 35
  2. B. 34 and 36
  3. C. 35 and 36
  4. D. 35 and 37

Correct answer: C. 35 and 36

Row by row: row 1 has 2 entries and rows 2..11 have 3 each, so 2 + 30 = 32 entries precede row 12, whose entries are (12, 11), (12, 12), (12, 13): index 35. Column by column: column 1 has 2 entries and columns 2..12 have 3 each, 2 + 33 = 35 entries before column 13, whose first entry is (12, 13): index 36. The two layouts are not symmetric for an off-diagonal element.

More Programming and Data Structures (GATE) questions

Exams that ask this topic