This is a C Program to implement online search. The Wagner–Fischer algorithm is a dynamic programming algorithm that measures the Levenshtein distance between two strings of characters.
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:
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.
#include <stdio.h>
#include <math.h>
int d[100][100];
#define MIN(x,y) ((x) < (y) ? (x) : (y))
main() {
int i, j, m, n, temp, tracker;
char s[] = "kitten";
char t[] = "sitting";
m = strlen(s);
n = strlen(t);
for (i = 0; i <= m; i++)
d[0][i] = i;
for (j = 0; j <= n; j++)
d[j][0] = j;
for (j = 1; j <= m; j++) {
for (i = 1; i <= n; i++) {
if (s[i - 1] == t[j - 1]) {
tracker = 0;
} else {
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]);
}
Output:
$ gcc WagnerFischer.c $ ./a.out The Levinstein distance is 3
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data Structures and Algorithms.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice Computer Science MCQs
- Apply for C Internship
- Watch Advanced C Programming Videos
- Practice BCA MCQs
- Apply for Computer Science Internship