UGC-NET Dec 2013 · Asymptotic Analysis & Recurrences

MCQ · 2 marks · Problem PROG-DIVC-0032

The longest common subsequence of the sequences $X=<A, B, C, B, D, A, B>$ and $Y=<B, D, C, A, B, A>$ has length
  1. A
    $2$
  2. B
    $3$
  3. C
    $4$
  4. D
    $5$

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

Show the worked solution\[\boxed{c[i,j]=\begin{cases}c[i-1,j-1]+1 & x_i=y_j\\ \max(c[i-1,j],\,c[i,j-1]) & x_i\ne y_j\end{cases}}\]Filling the \(7\times6\) table for \(X=ABCBDAB\), \(Y=BDCABA\) gives \(c[7,6]=4\). One LCS of length 4 is \(BCBA\): in \(X\) at positions 2, 3, 4, 6 and in \(Y\) at positions 1, 3, 5, 6. No common subsequence of length 5 exists.Answer: C

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