Question
Consider a table , where the elements , , represent the cost of the optimal solutions of different subproblems of a problem that is being solved using a dynamic programming algorithm. The recursive formulation to compute the table entries is as follows:
Consider the following two algorithms to compute entries of . Assume that for both the algorithms, for all , has been initialized to .
Algorithm B1:
For i = 1, 2, ..., n
For j = 1, 2, ..., n
T[i][j] = 2*T[i - 1][j] + 3*T[i][j - 1]
Algorithm B2:
For s = 2, 3, ..., 2n
For i = 1, 2, ..., n
For j = 1, 2, ..., n
If (i + j == s)
T[i][j] = 2*T[i - 1][j] + 3*T[i][j - 1]
Algorithm , is said to be correct if and only if it calculates the correct values of , for all , (as per the recursive formulation) at the end of the execution of the algorithm .
Which one of the following statements is true?
Official answer and solution
- Official answer
- A
- From
- Official GATE 2026 answer key
Solution
Check whether the dependencies and are already computed before in both row-major order () and anti-diagonal order ().
To compute (), only and are needed:
- In Algorithm (row-major order), when at , row has already been completed (giving ) and column in row has just been completed (giving ).
- In Algorithm (anti-diagonal order by ), both dependencies and have index sum , so they were already computed during the previous outer-loop iteration (or initialized at ).
Therefore, both algorithms and respect the DAG of subproblem dependencies and are correct.
Option (A)
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2026 Computer Science and Information Technology - Session 2 (CS2)
- Question
- 39 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.