Question–>
https://practice.geeksforgeeks.org/problems/edit-distance3702/1
I understand the recusive cases that when the last character of both the string are same then recur foe m-1,n-1, but they are not equal then we have to take min of the recursive step of step insert delete and replace
but i cannot understand how the recurrence relation is formed–>
if (str1[m - 1] == str2[n - 1])
return editDist(str1, str2, m - 1, n - 1);
// If last characters are not same, consider all three
// operations on last character of first string,
// recursively compute minimum cost for all three
// operations and take minimum of three values.
return 1
+ min(editDist(str1, str2, m, n - 1), // Insert
editDist(str1, str2, m - 1, n), // Remove
editDist(str1, str2, m - 1,
n - 1) // Replace
);
when we are inserting is not the recurrence relation be
editDistance(m+1,n);