Java LCS LCSIterative(Character[] X, int i, Character Y[], int j, int c[][])

Here you can find the source of LCSIterative(Character[] X, int i, Character Y[], int j, int c[][])

Description

LCS Iterative

License

Open Source License

Declaration

private static void LCSIterative(Character[] X, int i, Character Y[],
            int j, int c[][]) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static void LCSIterative(Character[] X, int i, Character Y[],
            int j, int c[][]) {
        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]);
                }// w w  w .  j a  v a2s  . co  m
            }
        }
    }
}

Related

  1. lcs2(int[] A, int[] B, int m, int n)
  2. lcs3(int[] A, int[] B)
  3. lcs4(int[] A, int[] B)
  4. LCSAlgorithm(String a, String b)
  5. lcse(String str1, String str2)
  6. LCSRecursive(Character[] X, int i, Character Y[], int j, int c[][])