Professional Documents
Culture Documents
SUBSEQUENCE(LCS)
Presented by
PRINCE KUMAR
MT/CS/10005/18
• The longest common subsequence (LCS)
problem is the problem of finding the
longest subsequence common to all
sequences in a set of sequences (often
just two sequences).
String 1: a b c d e f g h i j
String 2: f c d g i
LCS -> c d g i
LCS IS IMPLEMENTED BY TWO
WAYS:-
ALGO:
if (A[i]==B[j])
LCS (i,j)=1+LCS[i-1,j-1]
else
LCS[i,j]=max(LCS[i-1,j],LCS[i,j-1])
A b d /0
0 1 2
a b c d
B a b c d /0 0 1 2 3 4
0 1 2 3 4
0 0 0 0 0 0
1 0 0 1 1 1
b
d 2 0 0 1 1 2
0 0 0 0 0 0
b 1 0 0 1 1 1
d 2 0 0 1 1 2