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 6–10 of 15

Q6GATE 2014 (Session 2)2 marksNAT
Consider two strings A="qpqrr" and B="pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.

Q7GATE 20112 marksMCQ−0.67 if wrong
Four matrices M1, M2, M3 and M4 are dimensions p x q, q x r, r x s and s x t respectively can be multiplied in several ways with different number of total scalar multiplications. For example When multiplied as ((M1×M2)×(M3×M4)((M_{1} \times M_{2})\times (M_{3}\times M_{4}) the total number of scalar multiplications is pqr+rst+prt. When multiplied as (((M1×M2)×M3)×M4)(((M_{1}\times M_{2})\times M_{3})\times M_{4}) , the total number of scalar multiplications is pqr+prs+pst. If p=10, q=100, r=20, s=5 and t=80, then the minimum number of scalar multiplications needed is

Q8GATE 20111 markMCQ−0.33 if wrong
An algorithm to find the length of the longest monotonically increasing sequence of numbers in an array A[0 :n-1] is given below.
Let Li denote the length of the longest monotonically increasing sequence starting at index i in the array

Initialize Ln−1=1L_{n-1}=1.
For all ii such that 0≤i≤n−20\le i\le n-2
Li={1+Li+1if A[i]<A[i+1]1OtherwiseL_i=\begin{cases}1+L_{i+1} & \text{if } A[i]\lt A[i+1]\\ 1 & \text{Otherwise}\end{cases}
Finally the length of the longest monotonically increasing sequence is Max(L0,L1,…,Ln−1)\text{Max}\left(L_0, L_1, \ldots, L_{n-1}\right).
Which of the following statements is TRUE?

Q9GATE 20102 marksMCQ−0.67 if wrong
The weight of a sequence a0,a1,...,an−1a_{0},a_{1},...,a_{n-1} of real numbers is defined as a0+a1/2+...+an−1/2n−1a_{0}+a_{1}/2+...+a_{n-1}/2^{n-1} A subsequence of a sequence is obtained by deleting some elements from the sequence, keeping the order of the remaining elements the same. Let X denote the maximum possible weight of a subsequence of a0,a1,...,an−1a_{0},a_{1},...,a_{n-1} and Y the maximum possible weight of a subsequence of a1,a2,...,an−1a_{1},a_{2},...,a_{n-1}. Then X is equal to

Q10GATE 20092 marksMCQ−0.67 if wrong
A sub-sequence of a given sequence is just the given sequence with some elements (possibly none or all) left out. We are given two sequences X[m] and Y[n] of lengths m and n, respectively, with indexes of X and Y starting from 0.

We wish to find the length of the longest common sub-sequence (LCS) of x[m] and Y[n] as l(m,n), where an incomplete recursive definition for the function l(i,j) to compute the length of the LCS of x[m] and Y[n] is given below:
l(i, j) = 0, if either i=0 or j=0
l(i, j) = expr1, if i,j>0 and x [i-1] = Y [j -1]
l(i, j) = expr2, if i,j>0 and x [i-1] != Y [j -1]
The values of l(i,j) could be obtained by dynamic programming based on the correct recursive definition of l(i,j) of the form given above, using an array L[M,N], where M = m+1 and N=n+1, such that L[i,j] = l(i,j).

Which one of the following statements would be TRUE regarding the dynamic programming solution for the recursive definition of l(i,j)?

Keep practising

Topics in Algorithms

All CS topics ›