GATE Computer ScienceHardGATE CSE

The non-zero elements of a 30 × 30 tridiagonal matrix (non-zeros only where |i − j| ≤ 1, indices 1-based) are stored row by row in a 1-D array starting at address 2000, 4 bytes each. What is the address of A[17][18]?

  1. A. 2200
  2. B. 2196
  3. C. 2192
  4. D. 2208

Correct answer: B. 2196

Rows 1..16 hold 2 + 3·15 = 47 elements; within row 17 the element A[17][18] is the 3rd (index 2), so offset 49 and address 2000 + 4·49 = 2196.

More Programming and Data Structures (GATE) questions

Exams that ask this topic