Java Utililty Methods LCS

List of utility methods to do LCS

Description

The list of methods to do LCS are organized into topic(s).

Method

intlcs(String str1, String str2)
lcs
int len1 = str1.length();
int len2 = str2.length();
int c[][] = new int[len1 + 1][len2 + 1];
for (int i = 0; i <= len1; i++) {
    for (int j = 0; j <= len2; j++) {
        if (i == 0 || j == 0) {
            c[i][j] = 0;
        } else if (str1.charAt(i - 1) == str2.charAt(j - 1)) {
...
intlcs(String X, String Y, int m, int n)
lcs
int[][] L = 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)
            L[i][j] = 0;
        else if (X.charAt(i - 1) == Y.charAt(j - 1))
            L[i][j] = L[i - 1][j - 1] + 1;
        else
...
intlcs1(int[] A, int[] B)
lcs
return lcs1impl(A, B, 0, 0);
intlcs2(int[] A, int[] B, int m, int n)
lcs
if (m == 0 || n == 0)
    return 0;
if (A[m - 1] == B[n - 1])
    return 1 + lcs2(A, B, m - 1, n - 1);
else
    return Math.max(lcs2(A, B, m, n - 1), lcs2(A, B, m - 1, n));
intlcs3(int[] A, int[] B)
lcs
int[][] M = new int[A.length][B.length];
int[] S = new int[Math.max(A.length, B.length)];
for (int i = 0; i < A.length; ++i) {
    for (int j = 0; j < B.length; ++j) {
        M[i][j] = -1;
for (int i = 0; i < S.length; ++i) {
...
intlcs4(int[] A, int[] B)
lcs
int[][] M = new int[A.length + 1][B.length + 1];
for (int i = 0; i < A.length; ++i) {
    M[i][0] = 0;
for (int j = 0; j < B.length; ++j) {
    M[0][j] = 0;
for (int i = 1; i <= A.length; ++i) {
...
StringLCSAlgorithm(String a, String b)
LCS Algorithm
int n = a.length();
int m = b.length();
int S[][] = new int[n + 1][m + 1];
int R[][] = new int[n + 1][m + 1];
int ii, jj;
for (ii = 0; ii <= n; ++ii) {
    S[ii][0] = 0;
    R[ii][0] = UP;
...
Stringlcse(String str1, String str2)
lcse
if (null == str1 || null == str2 || str1.equals("") || str2.equals("")) {
    return "";
char[] chs1 = str1.toCharArray();
char[] chs2 = str2.toCharArray();
int[][] dp = getDp(chs1, chs2);
int m = chs1.length - 1;
int n = chs2.length - 1;
...
voidLCSIterative(Character[] X, int i, Character Y[], int j, int c[][])
LCS Iterative
for (int a = 1; a <= i; ++a) {
    for (int b = 1; b <= j; ++b) {
        if (X[a - 1] == Y[b - 1]) {
            c[a][b] = 1 + c[a - 1][b - 1];
        } else {
            c[a][b] = Math.max(c[a - 1][b], c[a][b - 1]);
intLCSRecursive(Character[] X, int i, Character Y[], int j, int c[][])
LCS Recursive
if (c[i][j] == Integer.MIN_VALUE) {
    if (X[i - 1].equals(Y[j - 1])) {
        c[i][j] = 1 + LCSRecursive(X, i - 1, Y, j - 1, c);
    } else {
        c[i][j] = Math.max(LCSRecursive(X, i - 1, Y, j, c), LCSRecursive(X, i, Y, j - 1, c));
return c[i][j];
...