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

Based on the code below, add a function to print the matix 

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 21

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!