SE 504 Spring 2019
Prog. Assg. #1: Longest Common Subsequences
Due: Noon, May 4

An instance of the Java class LongComSubseq_504_S19, instantiated using a pair of Strings x and y, is intended to be able to provide information about longest common subsequences (LCS's) of any prefixes of x and y.

Letting x(m) and y(n) refer to the prefixes of x and y of lengths m and n, respectively, the kinds of information that such an object should be able to provide include these:

Let x(m) = x0x1...xm-1 and y(n) = y0y1...yn-1. Then a matching of x(m) and y(n) is a pair of mappings (f,g), where, for some k≥0, f : [0..k) ⟶ [0..m) and g : [0..k) ⟶ [0..n) such that both f and g are increasing and, for all i, 0≤i<k, xf.i = yg.i. To emphasize its length, we call this a k-matching. A k-matching of x(m) and y(n) is maximum if no (k+1)-matching exists. Of course, the length of a maximum matching corresponds to the length of an LCS.

As an example, consider

    0   1   2   3   4   5   6   7   8   9
  +---+---+---+---+---+---+---+---+---+---+
x | a | a | b | a | c | b | a | c | b | a | 
  +---+---+---+---+---+---+---+---+---+---+

    0   1   2   3   4   5   6   7   8
  +---+---+---+---+---+---+---+---+---+
y | c | a | c | a | b | b | c | c | a | 
  +---+---+---+---+---+---+---+---+---+

Then the following 5-matching is consistent with the fact that x0x3x5x8x9 = aabba = y1y3y4y5y8

   0   1   2   3   4
  +---+---+---+---+---+
f | 0 | 3 | 5 | 8 | 9 |
  +---+---+---+---+---+

    0   1   2   3   4
  +---+---+---+---+---+
g | 1 | 3 | 4 | 5 | 8 |
  +---+---+---+---+---+

Your job is to complete the class, as the source code given to you includes two stubbed methods, one of which is intended to compute an LCS and the other of which is intended to compute a maximum matching. As a technical detail, a matching is to be represented by an array of type int[][] of length two. Its two elements (each of type int[], of course) are to correspond to what we called f and g above.

The method that computes the LLCS function (as described in class) is given to you. You can make use of the matrix that it produces (which is stored in an instance variable) to compute an LCS or a maximum matching. You can use a maximum matching to compute an LCS, and vice versa.

Your source code is expected to be augmented by comments that describe loop invariants and bound functions.

For purposes of testing your work, you are provided with the Java application LongComSubseq_Tester.