SlideShare a Scribd company logo
1 of 45
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

More Related Content

What's hot

Solovay Kitaev theorem
Solovay Kitaev theoremSolovay Kitaev theorem
Solovay Kitaev theoremJamesMa54
 
IIT Jam math 2016 solutions BY Trajectoryeducation
IIT Jam math 2016 solutions BY TrajectoryeducationIIT Jam math 2016 solutions BY Trajectoryeducation
IIT Jam math 2016 solutions BY TrajectoryeducationDev Singh
 
Iit jam 2016 physics solutions BY Trajectoryeducation
Iit jam 2016 physics solutions BY TrajectoryeducationIit jam 2016 physics solutions BY Trajectoryeducation
Iit jam 2016 physics solutions BY TrajectoryeducationDev Singh
 
Solving the energy problem of helium final report
Solving the energy problem of helium final reportSolving the energy problem of helium final report
Solving the energy problem of helium final reportJamesMa54
 
Fast and efficient exact synthesis of single qubit unitaries generated by cli...
Fast and efficient exact synthesis of single qubit unitaries generated by cli...Fast and efficient exact synthesis of single qubit unitaries generated by cli...
Fast and efficient exact synthesis of single qubit unitaries generated by cli...JamesMa54
 
Hideitsu Hino
Hideitsu HinoHideitsu Hino
Hideitsu HinoSuurist
 
Tetsunao Matsuta
Tetsunao MatsutaTetsunao Matsuta
Tetsunao MatsutaSuurist
 
Hiroyuki Sato
Hiroyuki SatoHiroyuki Sato
Hiroyuki SatoSuurist
 
All pair shortest path by Sania Nisar
All pair shortest path by Sania NisarAll pair shortest path by Sania Nisar
All pair shortest path by Sania NisarSania Nisar
 
Hiroaki Shiokawa
Hiroaki ShiokawaHiroaki Shiokawa
Hiroaki ShiokawaSuurist
 
MCQs Ordinary Differential Equations
MCQs Ordinary Differential EquationsMCQs Ordinary Differential Equations
MCQs Ordinary Differential EquationsDrDeepaChauhan
 
Chapter 6 algebraic expressions iii
Chapter 6   algebraic expressions iiiChapter 6   algebraic expressions iii
Chapter 6 algebraic expressions iiiKhusaini Majid
 
Number theoretic-rsa-chailos-new
Number theoretic-rsa-chailos-newNumber theoretic-rsa-chailos-new
Number theoretic-rsa-chailos-newChristos Loizos
 
Aieee 2003 maths solved paper by fiitjee
Aieee 2003 maths solved paper by fiitjeeAieee 2003 maths solved paper by fiitjee
Aieee 2003 maths solved paper by fiitjeeMr_KevinShah
 
BITSAT 2018 Question Bank - Maths
BITSAT 2018 Question Bank - MathsBITSAT 2018 Question Bank - Maths
BITSAT 2018 Question Bank - Mathsyash bansal
 

What's hot (17)

Solovay Kitaev theorem
Solovay Kitaev theoremSolovay Kitaev theorem
Solovay Kitaev theorem
 
IIT Jam math 2016 solutions BY Trajectoryeducation
IIT Jam math 2016 solutions BY TrajectoryeducationIIT Jam math 2016 solutions BY Trajectoryeducation
IIT Jam math 2016 solutions BY Trajectoryeducation
 
Iit jam 2016 physics solutions BY Trajectoryeducation
Iit jam 2016 physics solutions BY TrajectoryeducationIit jam 2016 physics solutions BY Trajectoryeducation
Iit jam 2016 physics solutions BY Trajectoryeducation
 
Solving the energy problem of helium final report
Solving the energy problem of helium final reportSolving the energy problem of helium final report
Solving the energy problem of helium final report
 
Finite frequency H∞control design for nonlinear systems
Finite frequency H∞control design for nonlinear systemsFinite frequency H∞control design for nonlinear systems
Finite frequency H∞control design for nonlinear systems
 
Fast and efficient exact synthesis of single qubit unitaries generated by cli...
Fast and efficient exact synthesis of single qubit unitaries generated by cli...Fast and efficient exact synthesis of single qubit unitaries generated by cli...
Fast and efficient exact synthesis of single qubit unitaries generated by cli...
 
Hideitsu Hino
Hideitsu HinoHideitsu Hino
Hideitsu Hino
 
Tetsunao Matsuta
Tetsunao MatsutaTetsunao Matsuta
Tetsunao Matsuta
 
Hiroyuki Sato
Hiroyuki SatoHiroyuki Sato
Hiroyuki Sato
 
Integration SPM
Integration SPMIntegration SPM
Integration SPM
 
All pair shortest path by Sania Nisar
All pair shortest path by Sania NisarAll pair shortest path by Sania Nisar
All pair shortest path by Sania Nisar
 
Hiroaki Shiokawa
Hiroaki ShiokawaHiroaki Shiokawa
Hiroaki Shiokawa
 
MCQs Ordinary Differential Equations
MCQs Ordinary Differential EquationsMCQs Ordinary Differential Equations
MCQs Ordinary Differential Equations
 
Chapter 6 algebraic expressions iii
Chapter 6   algebraic expressions iiiChapter 6   algebraic expressions iii
Chapter 6 algebraic expressions iii
 
Number theoretic-rsa-chailos-new
Number theoretic-rsa-chailos-newNumber theoretic-rsa-chailos-new
Number theoretic-rsa-chailos-new
 
Aieee 2003 maths solved paper by fiitjee
Aieee 2003 maths solved paper by fiitjeeAieee 2003 maths solved paper by fiitjee
Aieee 2003 maths solved paper by fiitjee
 
BITSAT 2018 Question Bank - Maths
BITSAT 2018 Question Bank - MathsBITSAT 2018 Question Bank - Maths
BITSAT 2018 Question Bank - Maths
 

Viewers also liked

Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmDarshit Metaliya
 
Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common SubsequenceSwati Swati
 
Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common SubsequenceKrishma Parekh
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplicationRespa Peter
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingSkiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingzukun
 
Introducing LCS to Digital Design Verification
Introducing LCS to Digital Design VerificationIntroducing LCS to Digital Design Verification
Introducing LCS to Digital Design VerificationDaniele Loiacono
 
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...Tosin Amuda
 
The Maximum Subarray Problem
The Maximum Subarray ProblemThe Maximum Subarray Problem
The Maximum Subarray ProblemKamran Ashraf
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous ComputingKamran Ashraf
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11Kumar
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesKumar Avinash
 
Activity selection problem
Activity selection problemActivity selection problem
Activity selection problemSumita Das
 
Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesTalha Shaikh
 

Viewers also liked (20)

Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) Algorithm
 
Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common Subsequence
 
Longest Common Subsequence
Longest Common SubsequenceLongest Common Subsequence
Longest Common Subsequence
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Skiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programmingSkiena algorithm 2007 lecture16 introduction to dynamic programming
Skiena algorithm 2007 lecture16 introduction to dynamic programming
 
Introducing LCS to Digital Design Verification
Introducing LCS to Digital Design VerificationIntroducing LCS to Digital Design Verification
Introducing LCS to Digital Design Verification
 
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
 
The Maximum Subarray Problem
The Maximum Subarray ProblemThe Maximum Subarray Problem
The Maximum Subarray Problem
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous Computing
 
LCS Problem
LCS ProblemLCS Problem
LCS Problem
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 
The selection sort algorithm
The selection sort algorithmThe selection sort algorithm
The selection sort algorithm
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Algorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class NotesAlgorithm Analysis and Design Class Notes
Algorithm Analysis and Design Class Notes
 
Activity selection problem
Activity selection problemActivity selection problem
Activity selection problem
 
Comparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategiesComparitive Analysis of Algorithm strategies
Comparitive Analysis of Algorithm strategies
 
Knapsack
KnapsackKnapsack
Knapsack
 

Similar to Longest common subsequence lcs

lecture 5 courseII (6).pptx
lecture 5 courseII (6).pptxlecture 5 courseII (6).pptx
lecture 5 courseII (6).pptxAYMENGOODKid
 
Application of parallel hierarchical matrices and low-rank tensors in spatial...
Application of parallel hierarchical matrices and low-rank tensors in spatial...Application of parallel hierarchical matrices and low-rank tensors in spatial...
Application of parallel hierarchical matrices and low-rank tensors in spatial...Alexander Litvinenko
 
Counting Sort and Radix Sort Algorithms
Counting Sort and Radix Sort AlgorithmsCounting Sort and Radix Sort Algorithms
Counting Sort and Radix Sort AlgorithmsSarvesh Rawat
 
Chapter 3: Linear Systems and Matrices - Part 3/Slides
Chapter 3: Linear Systems and Matrices - Part 3/SlidesChapter 3: Linear Systems and Matrices - Part 3/Slides
Chapter 3: Linear Systems and Matrices - Part 3/SlidesChaimae Baroudi
 
Trigonometric ratios and identities 1
Trigonometric ratios and identities 1Trigonometric ratios and identities 1
Trigonometric ratios and identities 1Sudersana Viswanathan
 
Identification of unknown parameters and prediction with hierarchical matrice...
Identification of unknown parameters and prediction with hierarchical matrice...Identification of unknown parameters and prediction with hierarchical matrice...
Identification of unknown parameters and prediction with hierarchical matrice...Alexander Litvinenko
 
1.6 Rational Expressions
1.6 Rational Expressions1.6 Rational Expressions
1.6 Rational Expressionssmiller5
 
Application of parallel hierarchical matrices for parameter inference and pre...
Application of parallel hierarchical matrices for parameter inference and pre...Application of parallel hierarchical matrices for parameter inference and pre...
Application of parallel hierarchical matrices for parameter inference and pre...Alexander Litvinenko
 
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptx
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptxAIOU Code 1429 Solved Assignment 1 Autumn 2022.pptx
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptxZawarali786
 
Exams in college algebra
Exams in college algebraExams in college algebra
Exams in college algebraRaymond Garcia
 
Lp model, simplex method
Lp model, simplex method   Lp model, simplex method
Lp model, simplex method praveenbabu63
 

Similar to Longest common subsequence lcs (20)

Chapter 31 logarithms
Chapter 31 logarithmsChapter 31 logarithms
Chapter 31 logarithms
 
lecture 5 courseII (6).pptx
lecture 5 courseII (6).pptxlecture 5 courseII (6).pptx
lecture 5 courseII (6).pptx
 
Application of parallel hierarchical matrices and low-rank tensors in spatial...
Application of parallel hierarchical matrices and low-rank tensors in spatial...Application of parallel hierarchical matrices and low-rank tensors in spatial...
Application of parallel hierarchical matrices and low-rank tensors in spatial...
 
Estadistica U4
Estadistica U4Estadistica U4
Estadistica U4
 
Counting Sort and Radix Sort Algorithms
Counting Sort and Radix Sort AlgorithmsCounting Sort and Radix Sort Algorithms
Counting Sort and Radix Sort Algorithms
 
Chapter 3: Linear Systems and Matrices - Part 3/Slides
Chapter 3: Linear Systems and Matrices - Part 3/SlidesChapter 3: Linear Systems and Matrices - Part 3/Slides
Chapter 3: Linear Systems and Matrices - Part 3/Slides
 
Correlation & regression uwsb
Correlation & regression   uwsbCorrelation & regression   uwsb
Correlation & regression uwsb
 
Correlation & regression
Correlation & regression Correlation & regression
Correlation & regression
 
Trigonometric ratios and identities 1
Trigonometric ratios and identities 1Trigonometric ratios and identities 1
Trigonometric ratios and identities 1
 
Engineering Mechanics
Engineering MechanicsEngineering Mechanics
Engineering Mechanics
 
Identification of unknown parameters and prediction with hierarchical matrice...
Identification of unknown parameters and prediction with hierarchical matrice...Identification of unknown parameters and prediction with hierarchical matrice...
Identification of unknown parameters and prediction with hierarchical matrice...
 
Counting sort
Counting sortCounting sort
Counting sort
 
Trig packet1 000
Trig packet1 000Trig packet1 000
Trig packet1 000
 
Trig packet1 000
Trig packet1 000Trig packet1 000
Trig packet1 000
 
1.6 Rational Expressions
1.6 Rational Expressions1.6 Rational Expressions
1.6 Rational Expressions
 
Cs262 2006 lecture6
Cs262 2006 lecture6Cs262 2006 lecture6
Cs262 2006 lecture6
 
Application of parallel hierarchical matrices for parameter inference and pre...
Application of parallel hierarchical matrices for parameter inference and pre...Application of parallel hierarchical matrices for parameter inference and pre...
Application of parallel hierarchical matrices for parameter inference and pre...
 
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptx
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptxAIOU Code 1429 Solved Assignment 1 Autumn 2022.pptx
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptx
 
Exams in college algebra
Exams in college algebraExams in college algebra
Exams in college algebra
 
Lp model, simplex method
Lp model, simplex method   Lp model, simplex method
Lp model, simplex method
 

Recently uploaded

e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 

Recently uploaded (20)

e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 

Longest common subsequence lcs

  • 2. 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).
  • 3. 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 ?
  • 4. 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
  • 5. 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.
  • 6. 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.
  • 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 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𝟐 𝒎 )
  • 10. 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
  • 11. 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
  • 12. Facts OF LCS Dynamic programming a b b a = A = a x b matrix How many operations to compute AB ?
  • 13. Facts OF LCS Dynamic programming a b b c =
  • 14. Facts OF LCS Dynamic programming a b b a = Need to compute = O (a×b)
  • 16. To Compare DNA of two (or more ) Different organisms
  • 17. EXAMPLE Assume two DNA sequence 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 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]
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. 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
  • 24. 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]
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. 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
  • 31. 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
  • 32. 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
  • 33. 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
  • 34. 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
  • 36. 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
  • 37. 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
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. 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
  • 42. 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
  • 43. 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
  • 44. 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
  • 45. 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