GATE Computer ScienceHardGATE CS (PYQ pattern)

The edit distance between PNEUMONIA and AMMONIA is computed with insertion, deletion and substitution each costing 1. What is the minimum cost?

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

Correct answer: C. 4

The common suffix MONIA costs nothing, and PNEU → AM costs 4 (substitute P→A and N→M, delete E and U); the Levenshtein table confirms no cheaper script exists, giving 4. 6 = 9 + 7 − 2·LCS(=5) is the cost when substitution is not allowed (or costs 2); 2 is just the length difference.

More Algorithms questions

Exams that ask this topic