Question 6 (20 points): Consider the iterative routine that takes two strings as arguments and generates a two-dimension

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Question 6 (20 points): Consider the iterative routine that takes two strings as arguments and generates a two-dimension

Post by answerhappygod »

Question 6 20 Points Consider The Iterative Routine That Takes Two Strings As Arguments And Generates A Two Dimension 1
Question 6 20 Points Consider The Iterative Routine That Takes Two Strings As Arguments And Generates A Two Dimension 1 (92.62 KiB) Viewed 37 times
Question 6 (20 points): Consider the iterative routine that takes two strings as arguments and generates a two-dimensional integer array to keep the information to compute the longest common subsequence of the two strings; the function is provided here for your ready reference. int max (int a, int b) { if (a> b) return a; jt i→ ... else return b; } ... int lcs_length (char *A, char *B){ // Need a 2-D int array L, int i, j; int *L; int m= strlen(A), n = strlen(B); L = (int *) malloc ((m+0)*(n+0)*sizeof(int)); for (i=m;i>= 0; i--) for (j=n; j>= 0;j--) { if (A='\0' || B[j]='\0') L[i*m+j] = 0; else if (A B[j]) L[i*m+j]= 1+L[(i+1)*m+j+1]; else L[i*m+j]= max(L[(i+1)*m+j],L[i*m+j+1]); } // Write the code to navigate the array L to //print the LCS and to return the length of the LCS (a) Fill up the table above to show the L array for two input strings A = "nematode knowledge", B = "empty bottle". (b) Complete the last part of the code to print the LCS and return the length of LCS; show the LCS and its length as generated by your code for the above example.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply