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];
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];
Chapter3: Data Representation
Section: Chapter Questions
Problem 1PE
Related questions
Question
Hi I need help finding out manually with dynamic
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps
Knowledge Booster
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.Recommended textbooks for you
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning