Implement these two methods and call them from the main and print the return c.
ID: 3807346 • Letter: I
Question
Implement these two methods and call them from the main and print the return c. Pass X and Y as int [ ] x ={1,0,0,1,0,1,0,1} int [ ] y={0,1,0,1,1,0,1,1,0} Procedure LCS-Length(X,Y) m length X] n length[Y] for i: 0 to m do cli, 0] 0 for j 0 to n do c j] 0 for i 1 to m do for j 1 to n do if x[i] YU] then clij] c[i-1, j-1] +1 else if c i-1 cli i-11 then clij] cli-1 else cli c[ij-1] return c Procedure Print-L (c,X,Y,ij) 1 if i 0 orj 0 then return then nt- X,i-1 j-1) print Xlil else if cli-1, il> cli i-11 else Pring-LCS(c, xi,j-1)Explanation / Answer
#include<stdio.h>
int c[1000][1000];
void LCS_Length(int c[][1000],int x[],int xl,int y[],int yl)
{
int m,n,i,j;
m = xl;
n=yl;
for(i=0;i<m;i++)c[i][0]=0;
for(j=0;j<n;j++)c[0][j]=0;
for(i=1;i<m;i++)
{
for(j=1;j<n;j++)
{
if(x[i]==y[j])
{
c[i][j]=c[i-1][j-1]+1;
}
else if (c[i-1][j]>c[i][j-1])
{
c[i][j]=c[i-1][j];
}
else
c[i][j]=c[i][j-1];
}
}
//return c;
}
void print_lcs(int c[][1000],int x[],int xl,int y[],int yl,int i,int j)
{
if(i==0 || j==0)
return;
if(c[i][j]==c[i-1][j-1] && x[i]==y[j])
{
print_lcs(c,x,xl,y,yl,i-1,j-1);
printf("%d ",x[i]);
}
else if(c[i-1][j]>c[i][j-1])
{
print_lcs(c,x,xl,y,yl,i-1,j);
}
else
{
print_lcs(c,x,xl,y,yl,i,j-1);
}
}
int main()
{
int x[] = {1,0,0,1,0,1,0,1};
int y[] = {0,1,0,1,1,0,1,1,0};
LCS_Length(c,x,8,y,9);
//printing c
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<9;j++)
{
printf("%d ",c[i][j]);
}
printf(" ");
}
return 0;
}
output:-
0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 1 1
0 0 1 1 1 2 2 2 2
0 1 1 2 2 2 3 3 3
0 1 2 2 2 3 3 3 4
0 1 2 3 3 3 4 4 4
0 1 2 3 3 4 4 4 5
0 1 2 3 4 4 5 5 5
Process exited normally.
Press any key to continue . . .