Dynamic Programming questions

Q39

GATE CS 2026 CS-2Algorithm DesignMCQ2 marks−2/3 if wrong
Consider a table TT, where the elements T[i][j],0≤i,j≤nT[i][j], 0 \le i, j \le n, 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:

T[0][k]=T[k][0]=1for k=0,1,2,…,nT[0][k] = T[k][0] = 1 \quad \text{for } k = 0,1,2, \dots, n

T[i][j]=2T[i−1][j]+3T[i][j−1]for 1≤i,j≤nT[i][j] = 2T[i - 1][j] + 3T[i][j - 1] \quad \text{for } 1 \le i, j \le n

Consider the following two algorithms to compute entries of TT. Assume that for both the algorithms, for all 0≤i,j≤n0 \le i, j \le n, T[i][j]T[i][j] has been initialized to 1.

Algorithm B1B_1:
For i = 1, 2, ..., n
 For j = 1, 2, ..., n
 T[i][j] = 2T[i - 1][j] + 3T[i][j - 1]
Algorithm B2B_2:
For s = 2, 3, ..., 2n
 For i = 1, 2, ..., n
 For j = 1, 2, ..., n
 If (i + j == s)
 T[i][j] = 2T[i - 1][j] + 3T[i][j - 1]
Algorithm Bk,k∈{1,2}B_k, k \in \{1,2\} is said to be correct if and only if it calculates the correct values of T[i][j]T[i][j], for all 0≤i,j≤n0 \le i, j \le n, (as per the recursive formulation) at the end of the execution of the algorithm BkB_k.

Which one of the following statements is true?
Show answer without attempting

Answer: A

0/10 correct0 marks

Related topics in Algorithm Design