public class LCS extends java.lang.Object implements StringSimilarity
That is, given two strings A and B, this program will find the longest sequence of letters that are common and ordered in A and B.
There are only two reasons you are reading this:
In either case, you should either read an entire chapter of an algorithms textbook on the subject of dynamic programming, or you should consult a webpage that describes this particular algorithm. It is important, for example, that we use arrays of size |A|+1 x |B|+1.
This code is provided AS-IS. You may use this code in any way you see fit, EXCEPT as the answer to a homework problem or as part of a term project in which you were expected to arrive at this code yourself.
Copyright (C) 2005 Neil Jones.
Similarity computation added by Phiip R. Burns. 2007/10/24.
Constructor and Description |
---|
LCS()
Create LCS instance.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
LCSAlgorithm(java.lang.String a,
java.lang.String b) |
static double |
lcsSimilarity(java.lang.String s1,
java.lang.String s2)
Compute similarity of two strings using longest common subsequence.
|
double |
similarity(java.lang.String s1,
java.lang.String s2)
Compute similarity of two strings using longest common subsequence.
|
public static java.lang.String LCSAlgorithm(java.lang.String a, java.lang.String b)
public static double lcsSimilarity(java.lang.String s1, java.lang.String s2)
s1
- First string.s2
- Second string.public double similarity(java.lang.String s1, java.lang.String s2)
similarity
in interface StringSimilarity
s1
- First string.s2
- Second string.