Question

int editDist(char * firstString, char * secString, int table) { //Code to make a edit distance...

int editDist(char * firstString, char * secString, int table)
{
//Code to make a edit distance table
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Utility function to find minimum of three numbers

int min(int x, int y, int z)

{

return min(min(x, y), z);

}

int editDist(char* str1 , char* str2 , int m ,int n)

{

// If first string is empty, the only option is to

// insert all characters of second string into first

if (m == 0) return n;

// If second string is empty, the only option is to

// remove all characters of first string

if (n == 0) return m;

// If last characters of two strings are same, nothing

// much to do. Ignore last characters and get count for

// remaining strings.

if (str1[m-1] == str2[n-1])

return editDist(str1, str2, m-1, n-1);

// If last characters are not same, consider all three

// operations on last character of first string, recursively

// compute minimum cost for all three operations and take

// minimum of three values.

return 1 + min ( editDist(str1, str2, m, n-1), // Insert

editDist(str1, str2, m-1, n), // Remove

editDist(str1, str2, m-1, n-1) // Replace

);

}

int editDist(char *firstString, char *secString, int table)

{

return editDist(firstString, secString, table, table);

}

Add a comment
Know the answer?
Add Answer to:
int editDist(char * firstString, char * secString, int table) { //Code to make a edit distance...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT