Shortest path to transform one word into another

NEW ANSWER

Given the recent update, you could try A* with the Hamming distance as a heuristic. It’s an admissible heuristic since it’s not going to overestimate the distance

OLD ANSWER

You can modify the dynamic-program used to compute the Levenshtein distance to obtain the sequence of operations.

EDIT: If there are a constant number of strings, the problem is solvable in polynomial time. Else, it’s NP-hard (it’s all there in wikipedia) .. assuming your friend is talking about the problem being NP-hard.

EDIT: If your strings are of equal length, you can use Hamming distance.

Leave a Comment