Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Using unit-cost insertions, deletions and substitutions, what is the minimum number of operations needed to turn the string 'bccbba' into 'acacaab'?

  1. A. 5
  2. B. 3
  3. C. 7
  4. D. 4

Correct answer: A. 5

This is the Levenshtein (edit) distance, computed by the standard DP. A substitution costs one operation, so the insert-and-delete-only distance n + m − 2·LCS is larger whenever a substitution helps.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic