Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using c++ only, and provide all the four cases in the table, thank you. int edit_distance (string A, string B) { m = A.length(); n

image text in transcribedusing c++ only, and provide all the four cases in the table, thank you.

int edit_distance (string A, string B) { m = A.length(); n = B.length(); for (int i = m; i >= 0; i--) { for (int j = n; j >= 0; j--) { if (i == m) d[i][j] = 2 * (n - j);

else if (j == n) d[i][j] = 2 * (m - i);

else if (A[i] == B[j]) { d[i][j] = d[i + 1][j + 1]; }

else d[i][j] = min(2 + d[i][j + 1], min(2 + d[i + 1][j], 1 + d[i + 1][j + 1]));

} }

return d[0][0];

}

Experimental Analysis Re-implement edit_distance() without dynamic programming (using recursion only). Run the recursive solution and the dynamic programming solution on your machine to compare their running times (you will need to add code for printing out the running times). Provide the names of the test cases you have used and the time in seconds or milliseconds) for each test case. If you used test cases that you have created, then mention only the size of strings A and B. You must use at least 4 different test cases and the running time of the non-dynamic programming solution on at least three of the test cases must be greater than 1 second. Provide your answer in a table as follows: length of A length of B File Name (if available) Time (DP) Time (recursive) 1 2 3 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions