Page 1 of 1

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

Posted: Thu May 05, 2022 1:21 pm
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 39 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.