|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mhhe.clrs2e.LongestCommonSubsequence
Implements the dynamic-programming algorithm to find a longest common subsequence of two strings, as described in Section 15.4 of Introduction to Algorithms, Second edition.
Nested Class Summary | |
private static class |
LongestCommonSubsequence.Direction
Inner class for a typesafe enum pattern for directions in a two-dimensional array. |
Field Summary | |
private LongestCommonSubsequence.Direction[][] |
b
The table entry used in constructing an LCS of prefixes Xi and Yj, for 0 ≤ i ≤ m-1 and 0 ≤ j ≤ n-1. |
private int[][] |
c
The length of an LCS of a subproblem. |
private static LongestCommonSubsequence.Direction |
LEFT
|
private int |
m
How many entries are in X. |
private int |
n
How many entries are in Y. |
private static LongestCommonSubsequence.Direction |
UP
|
private static LongestCommonSubsequence.Direction |
UP_AND_LEFT
|
private java.lang.String |
x
The input X. |
Constructor Summary | |
LongestCommonSubsequence(java.lang.String x,
java.lang.String y)
Computes an LCS of two strings, allocating the instance variables and storing the result in them. |
Method Summary | |
private char |
index(java.lang.String z,
int k)
Returns a given character from a String . |
private void |
lcsLength(java.lang.String x,
java.lang.String y)
Computes an LCS of two strings, storing the result in the instance variables. |
private java.lang.String |
printLCS(int i,
int j)
Returns an LCS of prefixes Xi and Yj. |
java.lang.String |
toString()
Returns an LCS of X and Y as a String . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final LongestCommonSubsequence.Direction UP
private static final LongestCommonSubsequence.Direction LEFT
private static final LongestCommonSubsequence.Direction UP_AND_LEFT
private int[][] c
c[i][j]
is
the length of an LCS of prefixes Xi
and Yj, for 0 ≤ i
≤ m-1 and 0 ≤ j ≤
n-1.
private LongestCommonSubsequence.Direction[][] b
private final int m
private final int n
private final java.lang.String x
Constructor Detail |
public LongestCommonSubsequence(java.lang.String x, java.lang.String y)
x
- The string X.y
- The string Y.Method Detail |
private void lcsLength(java.lang.String x, java.lang.String y)
x
- The string X.y
- The string Y.private char index(java.lang.String z, int k)
String
.
Compensates for character positions in a String
being indexed from 0, rather than from 1 as in Section 15.4.
z
- A String
.k
- An index into z
, but starting from 1.
k
th character of
z
.private java.lang.String printLCS(int i, int j)
i
- Index into X.j
- Index into Y.
String
that is an LCS of
Xi and Yj.public java.lang.String toString()
String
.
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |