Questions: Longest Common Subsequence (LCS) Problem

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A greedy algorithm for LCS matches the first common character it finds, then continues from that point in both strings. On strings A = 'ABCB' and B = 'BACB', it matches 'B' at position A[1] and B[0], then 'C' and 'B', finding LCS length 3. Could it have done better?

ANo — greedy always finds the optimal LCS length
BNo — length 3 is the true LCS length, but greedy may have been lucky; on other inputs it can fail
CYes — the actual LCS is length 4, which greedy missed by committing to 'B' too early
DYes — but only because the strings have repeated characters, where greedy always fails
Question 2 Multiple Choice

In the LCS DP table, dp[i][j] represents:

AWhether characters A[i] and B[j] match
BThe length of the LCS of the entire strings A and B, computed by row i and column j
CThe length of the LCS of the first i characters of A and the first j characters of B
DThe number of characters skipped in A to reach position i in the LCS
Question 3 True / False

The LCS of two strings is generally unique — there is exactly one longest common subsequence.

TTrue
FFalse
Question 4 True / False

Every substring of a string is also a subsequence of that string, but not every subsequence is a substring.

TTrue
FFalse
Question 5 Short Answer

Why doesn't a greedy approach work for the LCS problem, and what does dynamic programming enable that greedy cannot?

Think about your answer, then reveal below.