For example, the Levenshtein distance between “kitten” and “sitting” is 3, since the following three edits change one into the other, and there is no way to do it with fewer than three edits.
Here is source code of the C++ Program to Implement Wagner and Fisher Algorithm for online String Matching. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
#define MIN(x,y) ((x) < (y) ? (x) : (y))
char s = "Sanfoundry";
char t = "Education";
m = strlen(s);
n = strlen(t);
d[i] = i;
d[j] = j;
if(s[i-1] == t[j-1])
tracker = 0;
tracker = 1;
temp = MIN((d[i-1][j]+1),(d[i][j-1]+1));
d[i][j] = MIN(temp,(d[i-1][j-1]+tracker));
printf("the Levinstein distance is %d\n",d[n][m]);
$ g++ WagnerFischer.cpp $ a.out the Levinstein distance is 9 ------------------ (program exited with code: 0) Press return to continue
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.