All mock tests are FREE till 31 December — register to save your progress
Unit 7 · Data Structures and Algorithms Paper 2 CS · December 2018

Consider two sequences X = ⟨0, 1, 2, 1, 3, 0, 1⟩ and Y = ⟨1, 3, 2, 0, 1, 0⟩. The length of the longest common subsequence of X and Y is

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: C. 4

Explanation

⟨1, 3, 0, 1⟩ is common to both. Length 5 is impossible: in X, 3 comes after every 2, so a subsequence cannot contain both 3, 2 in Y's order with extra elements. LCS = 4.

More Data Structures and Algorithms questions