Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

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

Correct answer: D. 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