GATE CS 2009 · Asymptotic Analysis & Recurrences

MCQ · 2 marks · Problem PROG-DIVC-0117

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)?
  1. A
    All elements L should be initialized to 0 for the values of l(i,j) to be properly computed.
  2. B
    The values of l(i,j) may be computed in a row major order or column major order of L(M,N).
  3. C
    The values of l(i,j) cannot be computed in either row major order or column major order of L(M,N).
  4. D
    L[p,q] needs to be computed before L[r,s] if either p<r or q<s.

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionOfficial GATE Answer Key: Option B.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/43476/gate2009-54

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com