Tuesday, November 29, 2016

count number of changes two make two strings identical dynamic programming

#include <iostream>
#include <string>
using namespace std;

int min(int x, int y, int z)
{
   return min(min(x, y), z);
}
int editDistance(string str1,string str2,int n,int m )
{
if(n==0)
return m;
if(m==0)
return n;
char a = str1[n-1];
char b = str2[m-1];
    if( a==b )
return editDistance(str1,str2,n-1,m-1);
else
return 1+min(editDistance(str1,str2,n,m-1),editDistance(str1,str2,n-1,m),editDistance(str1,str2,n-1,m-1));
}

int main()
{
 
 string str1 = "pawan";
 string str2 = "rawam";

cout<<editDistance(str1,str2,str1.length(),str2.length());

}

No comments:

Post a Comment

Contributors

Translate