GATE Computer ScienceHardGATE CS (PYQ pattern)

What is the length of the longest common subsequence of the three strings X = BDCABACDB, Y = ABCBDABDC and Z = BCADBDACB?

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

Correct answer: B. 5

Use the 3-dimensional table L[i][j][k] = L[i−1][j−1][k−1] + 1 when all three characters agree, else the maximum of the three one-step reductions; it ends with 5 (confirmed by running the DP). The LCS of any two strings is longer than the three-way LCS, so pairwise answers overestimate.

More Algorithms questions

Exams that ask this topic