GATE Computer ScienceVery hardGATE CS (PYQ pattern)

X = ABCBDAB and Y = BDCABA have longest common subsequences of length 4. How many DIFFERENT strings are shortest common supersequences of X and Y (strings of minimum length that contain both X and Y as subsequences)?

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 4

Correct answer: C. 3

Any SCS has length |X| + |Y| − LCS = 7 + 6 − 4 = 9. Enumerating with the DP (keep both branches on ties, collect the strings into a set) gives exactly 3 distinct length-9 supersequences; several LCS alignments lead to the same string, so counting LCSs or DP paths overcounts.

More Algorithms questions

Exams that ask this topic