GATE Computer ScienceVery hardGATE CS (PYQ pattern)

The strings X = XYXZYXZ and Y = YZXYXZY are given. Their longest common subsequences all have length 5. How many distinct strings of length 5 are common subsequences of both X and Y?

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

Correct answer: D. 3

Running the LCS table and collecting all optimal paths gives exactly three distinct strings: XYXZY, YXYXZ and YZYXZ (verified by exhaustive backtracking). Counting alignments instead of distinct strings would overcount, and counting only one path misses the others.

More Algorithms questions

Exams that ask this topic