Professional Documents
Culture Documents
LCS Algo
LCS Algo
1. The longest common subsequence (LCS) problem is the classic computer science
problem.
2. The longest common subsequence problem is the problem of finding the longest
subsequence common to all sequences in the set of sequences.
3. LCS is widely used by revision control systems and in biometrics.
4. DNA is represented as strings of the small alphabet, Sigma = {A, C, G, T}.
5. DNA strings can be changed by mutation by insertion of a character into string.
6. A longest common subsequence of two strings can represent the common ancestry of
the two strings.
Finding a LCS:
Example:
Solution:
1 2 3 4 5 6 7 8 9
A[i] A B C D B A C D F
B[j] C B A F
We will build c [i, j] and d [i, j]. Initially c [i, 0] ← 0 where I represents row and c [0, j] ← 0
where j represent the column. The c table will store some values and d table will store
directions.
Step 1:
Step 2:
As A [i] ≠ B [j]
i.e. 0 ≥ 0
C [i, j] = c [i – 1, j]
C [1, 1] = c [0, 1]
C [1, 1] = 0
D [i, j] = ↑
Step 3:
Let i = 1, j = 2 then
As A [i] ≠ B [j]
C[1, 2] = c [0, 2]
C[1, 2] = 0
D[i, j] = ↑
Continuing in this fashion we can fill up the table as shown in figure 10: