Given two sequences π and π: π = β¨π,π,π,π,π,π,πβ© π =β¦
2015
Given two sequencesΒ πΒ andΒ π:
π = β¨π,π,π,π,π,π,πβ©
π = β¨π,π,π,π,π,πβ©
The longest common subsequence of X and Y is:
- A.
β¨π,π,πβ©
- B.
β¨π,π,πβ©
- C.
β¨π,π,π,πβ©
- D.
β¨π,π,π,πβ©
Attempted by 271 students.
Show answer & explanation
Correct answer: D
Solution: The longest common subsequence is β¨π,π,π,πβ© (length 4).
Matching indices in X = β¨a, b, c, b, d, a, bβ©: positions 2(b), 3(c), 4(b), 6(a).
Matching indices in Y = β¨b, d, c, a, b, aβ©: positions 1(b), 3(c), 5(b), 6(a).
This gives the common subsequence β¨π,π,π,πβ© in both sequences.
Why it is longest:
Other candidate subsequences such as β¨π,π,πβ© or β¨π,π,πβ© have length 3 and can be extended to β¨π,π,π,πβ©, so they are not maximal.
Sequences that try to include two 'a' characters in order (for example β¨π,π,π,πβ©) fail because X does not have the required two 'a' occurrences after the chosen b and c in the correct order.
Therefore no common subsequence of length 5 exists, and β¨π,π,π,πβ© (length 4) is a longest common subsequence.