Merge pull request #102 from crazymerlyn/fix-edit-distance

Fix bugs in edit distance implementation
This commit is contained in:
Ashwek Swamy 2019-02-09 12:57:59 +05:30 committed by GitHub
commit caacc6c991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,7 @@ int editDist(string str1, string str2, int m, int n) {
//If last characters are same then continue
//for the rest of them.
if(str1[m-1] == str2[n-2])
if(str1[m-1] == str2[n-1])
return editDist(str1, str2, m-1, n-1);
//If last not same, then 3 possibilities
@ -63,7 +63,7 @@ int editDistDP(string str1, string str2, int m, int n) {
//If character same. Recur for remaining
else if(str1[i-1] == str2[j-1])
dp[i][j] == dp[i-1][j-1];
dp[i][j] = dp[i-1][j-1];
else
dp[i][j] = 1 + min(dp[i][j-1],//Insert
@ -80,8 +80,8 @@ int main() {
string str1 = "sunday";
string str2 = "saturday";
cout << editDist(str1, str1, str1.length(), str2.length()) << endl;
cout << editDistDP(str1, str1, str1.length(), str2.length()) << endl;
cout << editDist(str1, str2, str1.length(), str2.length()) << endl;
cout << editDistDP(str1, str2, str1.length(), str2.length()) << endl;
return 0;
}