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

Q40

GATE CS 2021 CS-1Algorithm DesignMSQ2 marks
Define RnR_n to be the maximum amount earned by cutting a rod of length nn meters into one or more pieces of integer length and selling them. For i > 0, let p[i] denote the selling price of a rod whose length is i meters. Consider the array of prices:
p[1] = 1, p[2] = 5, p[3] = 8, p[4] = 9, p[5] = 10, p[6] = 17, p[7] = 18
Which of the following statements is/are correct about R7R_7?
More than one option can be correct.
Show answer without attempting

Answer: A, C

Q31

GATE CS 2018 CSAlgorithm DesignMCQ2 marks−2/3 if wrong
Assume that multiplying a matrix G1G_1 of dimension p×qp \times q with another matrix G2G_2 of dimension q×rq \times r requires pqrpqr scalar multiplications. Computing the product of nn matrices G1G2G3…GnG_1 G_2 G_3 \dots G_n can be done by parenthesizing in different ways. Define GiGi+1G_i G_{i+1} as an explicitly computed pair for a given parenthesization if they are directly multiplied. For example, in the matrix multiplication chain G1G2G3G4G5G6G_1 G_2 G_3 G_4 G_5 G_6 using parenthesization (G1(G2G3))(G4(G5G6))(G_1(G_2 G_3))(G_4(G_5 G_6)), G2G3G_2 G_3 and G5G6G_5 G_6 are the only explicitly computed pairs.

Consider a matrix multiplication chain F1F2F3F4F5F_1 F_2 F_3 F_4 F_5, where matrices F1,F2,F3,F4F_1, F_2, F_3, F_4 and F5F_5 are of dimensions 2×25,25×3,3×16,16×12 \times 25, 25 \times 3, 3 \times 16, 16 \times 1 and 1×10001 \times 1000, respectively. In the parenthesization of F1F2F3F4F5F_1 F_2 F_3 F_4 F_5 that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are
Show answer without attempting

Answer: C

Q5

GATE CS 2017 CS-1Algorithm DesignMCQ1 mark−1/3 if wrong
Consider the following table:
AlgorithmsDesign Paradigms
(P) Kruskal(i) Divide and Conquer
(Q) Quicksort(ii) Greedy
(R) Floyd-Warshall(iii) Dynamic Programming
Match the algorithms to the design paradigms they are based on.
Show answer without attempting

Answer: C

Q38

GATE CS 2016 CS-2Algorithm DesignNAT2 marks
Let A1,A2,A3A_1, A_2, A_3, and A4A_4 be four matrices of dimensions 10×510 \times 5, 5×205 \times 20, 20×1020 \times 10, and 10×510 \times 5, respectively. The minimum number of scalar multiplications required to find the product A1A2A3A4A_1 A_2 A_3 A_4 using the basic matrix multiplication method is _________.
Show answer without attempting

Answer: 1500.0

Q13

GATE CS 2015 CS-1Algorithm DesignMCQ1 mark−1/3 if wrong
Match the following:

(P) Prim's algorithm for minimum spanning tree
(Q) Floyd-Warshall algorithm for all pairs shortest paths
(R) Mergesort
(S) Hamiltonian circuit

(i) Backtracking
(ii) Greedy method
(iii) Dynamic programming
(iv) Divide and conquer
Show answer without attempting

Answer: C

Q47

GATE CS 2015 CS-2Algorithm DesignMCQ2 marks−2/3 if wrong
Given below are some algorithms, and some algorithm design paradigms.

1. Dijkstra's Shortest Path
2. Floyd-Warshall algorithm to compute all pairs shortest path
3. Binary search on a sorted array
4. Backtracking search on a graph

i. Divide and Conquer
ii. Dynamic Programming
iii. Greedy design
iv. Depth-first search
v. Breadth-first search

Match the above algorithms on the left to the corresponding design paradigm they follow.
Show answer without attempting

Answer: C

Q37

GATE CS 2014 CS-2Algorithm DesignNAT2 marks
Consider two strings AA = "qpqrr" and BB = "pqprqrp". Let xx be the length of the longest common subsequence (not necessarily contiguous) between AA and BB and let yy be the number of such longest common subsequences between AA and BB. Then x+10yx + 10y = ___.
Show answer without attempting

Answer: 34

Q37

GATE CS 2014 CS-3Algorithm DesignNAT2 marks
Suppose you want to move from 0 to 100 on the number line. In each step, you either move right by a unit distance or you take a shortcut. A shortcut is simply a pre-specified pair of integers i,ji, j with i<ji < j. Given a shortcut i,ji, j if you are at position ii on the number line, you may directly move to jj. Suppose T(k)T(k) denotes the smallest number of steps needed to move from kk to 100. Suppose further that there is at most 1 shortcut involving any number, and in particular from 9 there is a shortcut to 15. Let yy and zz be such that T(9)=1+min⁡(T(y),T(z))T(9) = 1 + \min(T(y), T(z)). Then the value of the product yzyz is _____.
Show answer without attempting

Answer: 150

Q38

GATE CS 2014 CS-1Algorithm DesignMCQ2 marks−2/3 if wrong
Suppose a polynomial time algorithm is discovered that correctly computes the largest clique in a given graph. In this scenario, which one of the following represents the correct Venn diagram of the complexity classes P, NP and NP Complete (NPC)?
Show answer without attempting

Answer: D

Q41

GATE CS 2014 CS-1Algorithm DesignMCQ2 marks−2/3 if wrong
Consider the following C function in which size is the number of elements in the array E:
int MyX(int *E, unsigned int size)
{
  int Y = 0;
  int Z;
  int i, j, k;

  for(i = 0; i < size; i++)
      Y = Y + E[i];

  for(i = 0; i < size; i++)
      for(j = i; j < size; j++)
      {
          Z = 0;
          for(k = i; k <= j; k++)
              Z = Z + E[k];
          if (Z > Y)
              Y = Z;
      }
  return Y;
}
The value returned by the function MyX is the
Show answer without attempting

Answer: A

0/110 correct0 marks

Related topics in Algorithm Design