ProgrammingHardTCS NQT · Accenture

The edit distance (Levenshtein, insert/delete/replace each cost 1) between "kitten" and "sitting" is computed by the standard table. What is printed?

The edit distance (Levenshtein, insert/delete/replace each cost 1) between "kitten" and "sitting" is computed by the standard table. What is printed?
dp[i][0] = i; dp[0][j] = j
dp[i][j] = min(dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + (0 if same else 1))
Print dp[m][n]
  1. A. 3
  2. B. 5
  3. C. 2
  4. D. 4

Correct answer: A. 3

Turning kitten into sitting needs three operations: replace k with s, replace e with i, and insert g. Charging 2 for a replacement gives 5, the length difference is 2, and the longest common subsequence length is 4.

More Pseudocode and Code Tracing questions

Exams that ask this topic