Similar questions 1 more →
Dynamic Programming
![Question 54, GATE 2009: Store the LCS recurrence in L[m+1, n+1]. Which is true? A every cell must first be zero; B increasing row-major or column-major computation works; C neither works; D L[p, q] must precede L[r, s] whenever p<r OR q<s.](../../assets/questions/CS-2009-Q54-1.webp)
![Question 54, GATE 2009: Store the LCS recurrence in L[m+1, n+1]. Which is true? A every cell must first be zero; B increasing row-major or column-major computation works; C neither works; D L[p, q] must precede L[r, s] whenever p<r OR q<s.](../../assets/questions/CS-2009-Q54-2.webp)
![Question 54, GATE 2009: Store the LCS recurrence in L[m+1, n+1]. Which is true? A every cell must first be zero; B increasing row-major or column-major computation works; C neither works; D L[p, q] must precede L[r, s] whenever p<r OR q<s.](../../assets/questions/CS-2009-Q54-3.webp)
Answer & solution
Answer: B (no official key was published)
Initialize only the empty-prefix boundary L[0, j]=L[i, 0]=0. Every other L[i, j] depends on L[i−1, j−1] in the matching case, or on L[i−1, j] and L[i, j−1] in the nonmatching case. Increasing-index row-major order computes all predecessors first; increasing-index column-major order also does so. Therefore B. Initializing every cell to zero is not necessary (A), and C contradicts these valid orders. D overstates the dependency: p<r alone does not require an arbitrarily far-right cell L[p, q] before L[r, s]; its OR condition can even demand opposite orders for incomparable cells such as (1, 2) and (2, 1).
The dependency arrows point left, up or diagonally up-left. Both increasing row order and increasing column order place all those predecessor cells before the current cell. Only row 0 and column 0 require initialization; every interior cell can be assigned when reached. The proposed OR ordering in D is too strong: cells(1, 2) and(2, 1) would each be required before the other. Therefore B.