Consider the iterative routine that takes two strings as arguments and generates a two-dimensional integer array to keep
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Consider the iterative routine that takes two strings as arguments and generates a two-dimensional integer array to keep
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; ji→ else return b; } ... int les_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!