AFRICA
, then \(X[1..4)\) is FRI
and \(X[0..6)\) is AFRICA
itself.AFRICA
leaves us with the string ARIA
. So we may say that ARIA
is a subsequence of AFRICA
.AFRICA
is considered a subsequence of itself.DIN
is a common subsequence of DYNAMICPROGRAMMING
and DIVIDEANDCONQUER
.DYNAMICPROGRAMMING
and DIVIDEANDCONQUER
have DICOR
as an LCS. This is because DICOR
is their common subsequence and no common subsequence of length 6 exists.DICON
is another LCS, so LCS's are not unique.Trying to solve the problem in a straightforward manner, we could do the following
we keep track of the current longest LCS found so far
for each subsequence Z of X do
if Z is also a subsequence of Y then
update the current longest LCS if needed
However, this algorithm has to generate more than an exponential number of pairs of subsequences and check them for equality—an enormous amount as a function of m and n. We need a better way.
OPT
\((i, j)\) be the length of an LCS of \(X[i..m)\) and \(Y[j..n)\).