Longest common subsequence: Difference between revisions

m
Added definition of "incomparable" matches.
(Restored original string names of A and B, since coding samples were based on that assumption.)
m (Added definition of "incomparable" matches.)
Line 8:
An ordered pair (i, j) will be called a match if A[i] == B[j], where 0 <= i < m and 0 <= j < n.
 
Define athe strict Cartesian product-order (<) over these ordered pairsmatches, such that (i1, j1) < (i2, j2) iff i1 < j1 and i2 < j2. Defining (>) similarly, we can write m2 < m1 as m1 > m2.
 
If i1 <= j1 and i2 >= j2 (or if i1 >= i2 and i2 <= j2) then neither m1 < m2 nor m1 > m2 are possible; and m1, m2 are said to be "incomparable". Defining (<>) to denote this case, we write m1 <> m2.
Given such a product-order over a set of matches '''M''', a chain '''C''' is any subset of '''M''' where either p1 < p2 or p2 < p1, for distinct pairs p1 and p2 in '''C'''.
 
Given such a product-order over athe set of matches '''M''', a chain '''C''' is any subset of '''M''' where either p1m1 < p2m2 or p2m2 < p1,m1 for any pair of distinct pairselements p1m1 and p2m2 inof '''C'''.
Finding an '''LCS''' can then be stated as the problem of finding a chain of maximum cardinality over the set of matches '''M'''.
 
Finding an '''LCS''' can then be statedrestated as the problem of finding a chain of maximum cardinality over the set of matches '''M'''.
This set of matches can also be visualized as an m*n bit matrix, where each bit '''M[i, j]''' is True iff there is a match at the corresponding positions of strings A and B.
 
ThisThe set of matches can'''M''' alsocan be visualized as an m*n bit matrix, where each bit '''M[i, j]''' is True iff there is a match at the corresponding positions of strings A and B.
 
Then any chain '''C''' can be visualized as a monotonically increasing curve through those match bits which are set to True.
159

edits