Data Structures & AlgorithmsHardGATE CS

What is the edit distance (insert, delete, substitute; each cost 1) between DIAMETER and INTERVAL?

  1. A. 8
  2. B. 4
  3. C. 16
  4. D. 7

Correct answer: D. 7

Fill the DP table with D[i][j] = min(delete, insert, substitute-or-match); D[8][8] = 7. Allowing only inserts and deletes gives 16 − 2·LCS = 8 (as does position-by-position mismatch counting), 4 is the LCS itself and 16 the total length.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic