Questions: Edit Distance: Levenshtein Distance and DP

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

You are computing the edit distance between 'CA' and 'ABC'. What is dp[1][1] — the edit distance between the prefix 'C' and the prefix 'A'?

A0, because both substrings have length 1
B1, because one replacement transforms 'C' into 'A'
C2, because you must delete 'C' and then insert 'A'
DCannot be determined without computing the full table first
Question 2 Multiple Choice

A programmer wants to reduce the O(mn) space of the edit distance algorithm. They realize they can use only two rows instead of the full table. Which property of the recurrence makes this optimization valid?

AThe recurrence is linear, so intermediate results can be discarded
BEach cell dp[i][j] depends only on dp[i-1][j-1], dp[i-1][j], and dp[i][j-1] — the previous row and the current row so far
CThe strings must have equal length for the optimization to work
DThe optimization only applies when using memoization rather than tabulation
Question 3 True / False

The edit distance between two strings is symmetric: dist('kitten', 'sitting') equals dist('sitting', 'kitten').

TTrue
FFalse
Question 4 True / False

Edit distance and longest common subsequence (LCS) measure the same underlying relationship between strings — one just counts edits while the other counts shared characters.

TTrue
FFalse
Question 5 Short Answer

Explain what each of the three terms in the edit distance recurrence — dp[i-1][j-1]+1, dp[i-1][j]+1, dp[i][j-1]+1 — represents when A[i] ≠ B[j]. Why does each term add exactly 1?

Think about your answer, then reveal below.