File Edit Format View Help LONGEST COMMONE SUB SEQUENCE Given two sequences X and Y, we want to find Z i.e., the longest common subsequence (LCS) of both X and Y. Because we know that subsequences of interest are of length >= a and <= b, we threshold the LCS definition to |Z| in [a, b] (where |Z| is the sequence length). public class Solution S 2 static int longSub (String a, String b) { int m= a.length(); int n = b.length(); int 1CS[][] = new int[m + 1][n+ 1]; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i == 0 || j == 0) { lcs[i][j] = 0; else if (a.charAt(i - 1) == b.charAt(j - 1)) { 1cs[i][j] = 1cs[i-1][j - 1] + 1; } else{ 1cs[i][j] = Math.max (1CS [i-1][j], lcs[i][j - 1]); } } return 1CS[m][n];

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hi I need help finding out manually with dynamic programming What the longest common sequence would be For the following 2 strings. I have attached the code of the algorithm longest common sequence. And of the table showing the 2 input strings.

*dynamicPro - Notepad
File Edit Format View Help
LONGEST COMMONE SUB SEQUENCE
Given two sequences X and Y, we want to find Z i.e., the longest common subsequence (LCS) of both X and Y.
Because we know that subsequences of interest are of length >= a and <= b, we threshold the
LCS definition to |Z| in [a, b] (where |Z| is the sequence length).
public class Solution
S
2,
static int longSub (String a, String b)
{
int m = a.length();
int n = b.length();
int 1CS[][] = new int [m + 1] [n + 1];
for (int i = 0; i <= m; i++)
{
for (int j = 0; j <= n; j++)
{
if (i == 0 || j == 0)
{
lcs[i][j] = 0;
}
else if (a.charAt(i - 1) == b.charAt(j - 1))
{
lcs[i][j] = lcs[i - 1][j - 1] + 1;
}
else{
lcs[i][j] = Math.max (1CS [i-1][j], lcs[i][j - 1]);
}
return 1CS[m][n];
Transcribed Image Text:*dynamicPro - Notepad File Edit Format View Help LONGEST COMMONE SUB SEQUENCE Given two sequences X and Y, we want to find Z i.e., the longest common subsequence (LCS) of both X and Y. Because we know that subsequences of interest are of length >= a and <= b, we threshold the LCS definition to |Z| in [a, b] (where |Z| is the sequence length). public class Solution S 2, static int longSub (String a, String b) { int m = a.length(); int n = b.length(); int 1CS[][] = new int [m + 1] [n + 1]; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i == 0 || j == 0) { lcs[i][j] = 0; } else if (a.charAt(i - 1) == b.charAt(j - 1)) { lcs[i][j] = lcs[i - 1][j - 1] + 1; } else{ lcs[i][j] = Math.max (1CS [i-1][j], lcs[i][j - 1]); } return 1CS[m][n];
Use bottom-up dynamic programming on our Longest Common Subsequence to fill in the storage array below.
T
G
C
G
A
T
A
G
T
A
C
T
A
A
Transcribed Image Text:Use bottom-up dynamic programming on our Longest Common Subsequence to fill in the storage array below. T G C G A T A G T A C T A A
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Problems on Amortized Analysis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning