Question 13

The elements of the triangular array are stored as a vector in the order A[1, 1], A[2, 1], A[2, 2], A[3, 1], A[3, 2], A[3, 3] ......... A[n, n].

The elements of the triangular array are stored as a vector in the order A[1, 1], A[2, 1], A[2, 2], A[3, 1], A[3, 2], A[3, 3] ......... A[n, n]. Assuming that A[1, 1] is stored at location 1, addressing function for A[i, j] is given by:
  1. A(i−1)/2 + j
  2. B((i−1)*i)/2 + j
  3. C(i×i)/2 + j
  4. D(i*j−1)/2
Show answerHide answer

Correct answer: (B) ((i−1)*i)/2 + j

Explanation

Rows 1 to i−1 hold 1 + 2 + … + (i−1) = i(i−1)/2 elements. A[i, j] is the j-th element of row i, so its location is i(i−1)/2 + j. Check: A[1,1] gives 0 + 1 = 1.

From DSSSB TGT Computer Science Practice Set 3

This is question 13 of DSSSB TGT Computer Science Practice Set 3. 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.