LONGEST COMMON SUBSEQUENCE
(LCS)
Group Name:
LONGEST COMMON SUBSEQUENCE
What is Longest common subsequence ?
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).
LONGEST COMMON SUBSEQUENCE
Suppose you have a sequence
X = < A,B,C,D,E,F,G>
of elements over a finite set S.
A sequence Y = <B,C,E,G >
over S is called a subsequence of X if and only if it can be obtained from X by deleting
elements.
WHAT IS SUBSEQUENCES ?
LONGEST COMMON SUBSEQUENCE
WHAT IS COMMON SUBSEQUENCES ?
Suppose that X and Y are two sequences over a set S.
If , A=<A,B,C,E,D,G,F,H,K>
B=<A,B,D,F,H,K>
then a common subsequence of X and Y could be
Z=<A,F,K>
We say that Z is a common subsequence of X and Y if and only if
Z is a subsequence of X
Z is a subsequence of Y
LONGEST COMMON SUBSEQUENCE
THE LONGEST COMMON SUBSEQUENCE PROBLEM
Given two sequences X and Y over a set S, the longest common
subsequence problem asks to find a common subsequence of X
and Y that is of maximal length.
LONGEST COMMON SUBSEQUENCE
NAÏVE SOLUTION
Let X be a sequence of length m,
and Y a sequence of length n.
Check for every subsequence of X whether it is a subsequence of Y, and return the longest
common subsequence found.
There are 2m subsequences of X. Testing a sequences whether or not it is a subsequence
of Y takes O(n) time. Thus, the naïve algorithm would take O(n2m) time.
FACTS OF LCS
INPUT: two strings
OUTPUT: longest common subsequence
ACTGAACTCTGTGCACT
TGACTCAGCACAAAAAC
FACTS OF LCS
INPUT: two strings
OUTPUT: longest common subsequence
ACTGAACTCTGTGCACT
TGACTCAGCACAAAAAC
FACTS OF LCS
Brute Force
X= ABCBDAB
Y= BDCABA
Elements of X is m=7
Elements of Y is n=6
So, the complexity will calculate by O (n𝟐 𝒎
)
FACTS OF LCS
Brute Force
Strength
 Wide applicability, simplicity
 Reasonable algorithms for some important
problems such as searching, string matching, and
matrix multiplication
 Standard algorithms for simple computational
tasks such as sum and product of n numbers, and
finding maximum or minimum in a list
FACTS OF LCS
Brute Force
Weakness
 Brute Force approach rarely yields efficient
algorithms
 Some brute force algorithms are unacceptably
slow
 Brute Force approach is neither as constructive
nor creative as some other design techniques
Facts OF LCS
Dynamic programming
a
b
b
a
=
A = a x b matrix
How many operations to compute AB ?
Facts OF LCS
Dynamic programming
a
b
b
c
=
Facts OF LCS
Dynamic programming
a
b
b
a
=
Need to compute = O (a×b)
Work Examples
To Compare DNA of two (or more ) Different organisms
EXAMPLE
Assume two DNA sequence
X = {ATGCTTC}
Y = {GCTCA}
LCS EXAMPLE X = {ATGCTTC}
Y = {GCTCA}
A T G C T T C
G
C
T
C
A
1 2 3 4 5 6 7
1
2
3
4
5
Yj
Xi
0
0
LCS EXAMPLE
A T G C T T C
0 0 0 0 0 0 0 0
G 0
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
1 2 3 4 5 6 7
1
2
3
4
5
Yj
Xi
0
0
Z[j,i]
Here I = 1, j = 1
Z[1,1]
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y
A G
Not Match
1 2 3 4 5 6 70
0
Z[1,1]
Z[j-1, i]=Z[1-1, 1]= Z[0,1]
Z[j, i-1]=Z[1, 1-1]= Z[1,0]
Maximum of
two box
z[J-1, i] and
[J, i-1]
1
2
3
4
5
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y
A G
Not Match
Lets Take from Upper one
Arrow indicate from
where you Take the
maximum.
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
T G 0
Not Match
Lets Take from left one
Arrow indicate from
where you Take the
maximum.
arrow
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
G G
Match
arrow
When match arrow will
be diagonal because we
will increment the
value of this cell
Z[i-1, j-1] + 10 = 1
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
G G
Match
arrow
Incremented value X[i-1] Y[j-1]
1 2 3 4 5 6 7
1
2
3
4
5
0
0
Z[I,j] = Z[3,1]
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
C G 1
Not Match
Lets Take from left one
arrow
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
T G 1
Not Match
Lets Take from left one
arrow
0
0
1 2 3 4 5 6 7
1
2
3
4
5
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
T G 1
Not Match
Lets Take from left one
arrow
0
0
1 2 3 4 5 6 7
1
2
3
4
5
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
C G 1
Not Match
Lets Take from left one
arrow
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
A C 0
Not Match
Lets Take from left one
arrow
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
A C 0
Not Match
Lets Take from Upper one
arrow
0
0
1 2 3 4 5 6 7
1
2
3
4
5
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
G C 1
Not Match
Lets Take from left one
arrow
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
C C
Match
arrow
Increment Z[i-1,j-1]
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2
T 0
C 0
A 0
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
T C 2
Not Match
Lets Take from left one
arrow
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
X Y Max
T G 1
Not Match
Lets Take from left one
arrow
In the same way…
1 2 3 4 5 6 7
1
2
3
4
5
0
0
Traceback Approach
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
Firstly have to point out
highest value
For left and upper arrow
we will follow the
direction
For diagonal arrow we
will point out the
character for this cell.
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
LCS Z= G
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
LCS Z= GC
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
LCS Z= GCT
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
LCS Z= {GCTC}
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
Firstly have to point out
highest value
For left and upper arrow
we will follow the
direction
For diagonal arrow we
will point out the
character for this cell.
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
LCS Z= C
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
LCS Z= TC
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
LCS Z= CTC
1 2 3 4 5 6 7
1
2
3
4
5
0
0
LCS EXAMPLE
Xi A T G C T T C
YJ 0 0 0 0 0 0 0 0
G 0 0 0 1 1 1 1 1
C 0 0 0 1 2 2 2 2
T 0 0 1 1 2 3 3 3
C 0 0 1 1 2 3 3 4
A 0 1 1 1 2 3 3 4
X = {ATGCTTC}
Y = {GCTCA}
Yj
Xi
LCS Z= {GCTC}
1 2 3 4 5 6 7
1
2
3
4
5
0
0

Longest common subsequence lcs

  • 1.
  • 2.
    LONGEST COMMON SUBSEQUENCE Whatis Longest common subsequence ? 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).
  • 3.
    LONGEST COMMON SUBSEQUENCE Supposeyou have a sequence X = < A,B,C,D,E,F,G> of elements over a finite set S. A sequence Y = <B,C,E,G > over S is called a subsequence of X if and only if it can be obtained from X by deleting elements. WHAT IS SUBSEQUENCES ?
  • 4.
    LONGEST COMMON SUBSEQUENCE WHATIS COMMON SUBSEQUENCES ? Suppose that X and Y are two sequences over a set S. If , A=<A,B,C,E,D,G,F,H,K> B=<A,B,D,F,H,K> then a common subsequence of X and Y could be Z=<A,F,K> We say that Z is a common subsequence of X and Y if and only if Z is a subsequence of X Z is a subsequence of Y
  • 5.
    LONGEST COMMON SUBSEQUENCE THELONGEST COMMON SUBSEQUENCE PROBLEM Given two sequences X and Y over a set S, the longest common subsequence problem asks to find a common subsequence of X and Y that is of maximal length.
  • 6.
    LONGEST COMMON SUBSEQUENCE NAÏVESOLUTION Let X be a sequence of length m, and Y a sequence of length n. Check for every subsequence of X whether it is a subsequence of Y, and return the longest common subsequence found. There are 2m subsequences of X. Testing a sequences whether or not it is a subsequence of Y takes O(n) time. Thus, the naïve algorithm would take O(n2m) time.
  • 7.
    FACTS OF LCS INPUT:two strings OUTPUT: longest common subsequence ACTGAACTCTGTGCACT TGACTCAGCACAAAAAC
  • 8.
    FACTS OF LCS INPUT:two strings OUTPUT: longest common subsequence ACTGAACTCTGTGCACT TGACTCAGCACAAAAAC
  • 9.
    FACTS OF LCS BruteForce X= ABCBDAB Y= BDCABA Elements of X is m=7 Elements of Y is n=6 So, the complexity will calculate by O (n𝟐 𝒎 )
  • 10.
    FACTS OF LCS BruteForce Strength  Wide applicability, simplicity  Reasonable algorithms for some important problems such as searching, string matching, and matrix multiplication  Standard algorithms for simple computational tasks such as sum and product of n numbers, and finding maximum or minimum in a list
  • 11.
    FACTS OF LCS BruteForce Weakness  Brute Force approach rarely yields efficient algorithms  Some brute force algorithms are unacceptably slow  Brute Force approach is neither as constructive nor creative as some other design techniques
  • 12.
    Facts OF LCS Dynamicprogramming a b b a = A = a x b matrix How many operations to compute AB ?
  • 13.
    Facts OF LCS Dynamicprogramming a b b c =
  • 14.
    Facts OF LCS Dynamicprogramming a b b a = Need to compute = O (a×b)
  • 15.
  • 16.
    To Compare DNAof two (or more ) Different organisms
  • 17.
    EXAMPLE Assume two DNAsequence X = {ATGCTTC} Y = {GCTCA}
  • 18.
    LCS EXAMPLE X= {ATGCTTC} Y = {GCTCA} A T G C T T C G C T C A 1 2 3 4 5 6 7 1 2 3 4 5 Yj Xi 0 0
  • 19.
    LCS EXAMPLE A TG C T T C 0 0 0 0 0 0 0 0 G 0 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} 1 2 3 4 5 6 7 1 2 3 4 5 Yj Xi 0 0 Z[j,i] Here I = 1, j = 1 Z[1,1]
  • 20.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y A G Not Match 1 2 3 4 5 6 70 0 Z[1,1] Z[j-1, i]=Z[1-1, 1]= Z[0,1] Z[j, i-1]=Z[1, 1-1]= Z[1,0] Maximum of two box z[J-1, i] and [J, i-1] 1 2 3 4 5
  • 21.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y A G Not Match Lets Take from Upper one Arrow indicate from where you Take the maximum. 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 22.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max T G 0 Not Match Lets Take from left one Arrow indicate from where you Take the maximum. arrow 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 23.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max G G Match arrow When match arrow will be diagonal because we will increment the value of this cell Z[i-1, j-1] + 10 = 1 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 24.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max G G Match arrow Incremented value X[i-1] Y[j-1] 1 2 3 4 5 6 7 1 2 3 4 5 0 0 Z[I,j] = Z[3,1]
  • 25.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max C G 1 Not Match Lets Take from left one arrow 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 26.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max T G 1 Not Match Lets Take from left one arrow 0 0 1 2 3 4 5 6 7 1 2 3 4 5
  • 27.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max T G 1 Not Match Lets Take from left one arrow 0 0 1 2 3 4 5 6 7 1 2 3 4 5
  • 28.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max C G 1 Not Match Lets Take from left one arrow 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 29.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max A C 0 Not Match Lets Take from left one arrow 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 30.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max A C 0 Not Match Lets Take from Upper one arrow 0 0 1 2 3 4 5 6 7 1 2 3 4 5
  • 31.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max G C 1 Not Match Lets Take from left one arrow 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 32.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max C C Match arrow Increment Z[i-1,j-1] 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 33.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 T 0 C 0 A 0 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max T C 2 Not Match Lets Take from left one arrow 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 34.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi X Y Max T G 1 Not Match Lets Take from left one arrow In the same way… 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 35.
  • 36.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi Firstly have to point out highest value For left and upper arrow we will follow the direction For diagonal arrow we will point out the character for this cell. 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 37.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi LCS Z= G 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 38.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi LCS Z= GC 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 39.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi LCS Z= GCT 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 40.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi LCS Z= {GCTC} 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 41.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi Firstly have to point out highest value For left and upper arrow we will follow the direction For diagonal arrow we will point out the character for this cell. 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 42.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi LCS Z= C 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 43.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi LCS Z= TC 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 44.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi LCS Z= CTC 1 2 3 4 5 6 7 1 2 3 4 5 0 0
  • 45.
    LCS EXAMPLE Xi AT G C T T C YJ 0 0 0 0 0 0 0 0 G 0 0 0 1 1 1 1 1 C 0 0 0 1 2 2 2 2 T 0 0 1 1 2 3 3 3 C 0 0 1 1 2 3 3 4 A 0 1 1 1 2 3 3 4 X = {ATGCTTC} Y = {GCTCA} Yj Xi LCS Z= {GCTC} 1 2 3 4 5 6 7 1 2 3 4 5 0 0