Dynamic Programming: GATE CS Previous Year Questions

Dynamic Programming · Algorithms

15 questions · asked in 10 of 27 years (2000–2026)

MCQ 12 · NAT 31-mark 4 · 2-mark 11

2000Questions per year2026

Questions 1–5 of 15

Q1GATE 2026 (Session 2)2 marksMCQ−0.67 if wrong
Consider a table TT, where the elements T[i][j],0≤i,j≤nT[i][j], 0 \leq i, j \leq 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]=1 for k=0,1,2,…,nT[i][j]=2T[i−1][j]+3T[i][j−1] for 1≤i,j≤n\begin{array}{ll} T[0][k]=T[k][0]=1 & \text { for } k=0,1,2, \ldots, n \\ T[i][j]=2 T[i-1][j]+3 T[i][j-1] & \text { for } 1 \leq i, j \leq n \end{array}

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

Algorithm B1:For i=1,2,…,nFor j=1,2,…,nT[i][j]=2T[i−1][j]+3T[i][j−1]Algorithm B2:For s=2,3,…,2nFor i=1,2,…,nFor j=1,2,…,nIf i+j==sT[i][j]=2T[i−1][j]+3T[i][j−1]\begin{aligned} &\text{Algorithm } B_1: \\ &\quad \text{For } i = 1,2,\ldots,n \\ &\quad\quad \text{For } j = 1,2,\ldots,n \\ &\quad\quad\quad T[i][j] = 2T[i-1][j] + 3T[i][j-1] \\[6pt] &\text{Algorithm } B_2: \\ &\quad \text{For } s = 2,3,\ldots,2n \\ &\quad\quad \text{For } i = 1,2,\ldots,n \\ &\quad\quad\quad \text{For } j = 1,2,\ldots,n \\ &\quad\quad\quad\quad \text{If } i + j = = s \\ &\quad\quad\quad\quad\quad T[i][j] = 2T[i-1][j] + 3T[i][j-1] \end{aligned}

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 \leq i, j \leq 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?

Q2GATE 20182 marksMCQ−0.67 if wrong
Assume that multiplying a matrix G1 of dimension pxq with another matrix G2 of dimension qxr requires pqr scalar multiplications. Computing the product of n matrices G1G2G3...Gn can be done by parenthesizing in different ways. Define Gi Gi+1 as an explicitly computed pair for a given paranthesization if they are directly multiplied. For example, in the matrix multiplication chain G1G2G3G4G5G6 using parenthesization (G1(G2G3))(G4(G5G6)), G2G3 and G5G6 are the only explicitly computed pairs. Consider a matrix multiplication chain F1F2F3F4F5, where matrices F1, F2, F3, F4 and F5 are of dimensions 2x25, 25x3, 3x16, 16x1 and 1x1000, respectively. In the parenthesization of F1F2F3F4F5 that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are

Q3GATE 2016 (Session 2)1 markMCQ−0.33 if wrong
The Floyd-Warshall algorithm for all-pair shortest paths computation is based on

Q4GATE 2016 (Session 2)2 marksNAT
Let A1,A2,A3, and A4 be four matrices of dimensions 10x5, 5x20, 20x10, and 10x5, respectively. The minimum number of scalar multiplications required to find the product A1A2A3A4 using the basic matrix multiplication method is __________.

Q5GATE 2015 (Session 2)2 marksNAT
A Young tableau is a 2D array of integers increasing from left to right and from top to bottom. Any unfilled entries are marked with ∞\infty, and hence there cannot be any entry to the right of, or below a ∞\infty. The following Young tableau consists of unique entries.
12514346231012182531∞∞∞
When an element is removed from a Young tableau, other elements should be moved into its place so that the resulting table is still a Young tableau (unfilled entries may be filled in with a ∞\infty). The minimum number of entries (other than 1) to be shifted, to remove 1 from the given Young tableau is _______.

Keep practising

Topics in Algorithms

All CS topics ›