- GATE CS
- 2026–27 pattern practice
- Algorithms
- Dynamic programming
- Medium
What is the edit distance between "kitten" and "sitting", if insertion, deletion and substitution each cost 1?
Algorithm Design
Pick an option to check your answer.
Answer: A. Solution
Fill the standard edit-distance table, or find three edits that are clearly needed:
- kitten → sitten (substitute k with s)
- sitten → sittin (substitute e with i)
- sittin → sitting (insert g)
Two edits cannot work: the lengths differ (6 against 7), so at least one insertion is needed, and the first and fifth letters both differ. The DP table confirms the minimum is 3.
Why not the others
- misses one of the three required changes; the strings differ in length and in two letters.
- is the cost of a valid but non-optimal sequence of edits.
- counts mismatches position by position without allowing an insertion to realign the strings.