Question
Based on the code below, add a function to print the matix path: the result like this the original code: #include #include int levenshtein(const char
Based on the code below, add a function to print the matix path:
the result like this
the original code:
#include
#include
int levenshtein(const char *s, const char *t)
{
int ls = strlen(s), lt = strlen(t);
int d[ls + 1][lt + 1];
int i,j;
for (i = 0; i
for (j = 0; j
d[i][j] = -1;
int dist(i,j) {
if (d[i][j] >= 0) return d[i][j];
int x;
if (i == ls)
x = lt - j;
else if (j == lt)
x = ls - i;
else if (s[i] == t[j])
x = dist(i + 1, j + 1);
else {
x = dist(i + 1, j + 1);
int y;
if ((y = dist(i, j + 1))
if ((y = dist(i + 1, j))
x++;
}
return d[i][j] = x;
}
return dist(0, 0);
}
int main(void)
{
const char *s1 = "cat";
const char *s2 = "cs";
printf("distance between `%s' and `%s': %d ", s1, s2,levenshtein(s1, s2));
return 0;
}
c at | 01 2 3 cl 10 11 21 s 2 1| 11 21Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started