Solution: The Edit Distance Problem
This review provides a detailed analysis of the ways to solve the famous Edit Distance problem.
We'll cover the following...
We'll cover the following...
Solution #1: Brute Force
We process all the characters of each string one by one. There are two possibilities for every pair of characters being considered,
Pseudocode
IF str1[m-1]==str2[n-1]
Ignore them and get the count for remaining strings. So we call the function for lengths m-1 and n-1.
ELSE
we consider all operations on ‘str1’, consider all three operations on the last character of the first string, recursively compute the minimum cost for all three operations and return the minimum of the three values.
Insert: Call function for m and n-1
Remove: Call function for m-1 and n
Replace: Call function for m-1 and n-1
Time Complexity
The time complexity of this code is exponential, i.e. ...