Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed 

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

How can you defend against SQL injection attacks?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago