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

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
JamesMa54
 
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
 
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
Mr_KevinShah
 

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

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
zukun
 
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 Problem
Kamran Ashraf
 
Ubiquitous Computing
Ubiquitous ComputingUbiquitous Computing
Ubiquitous Computing
Kamran Ashraf
 
Greedy method class 11
Greedy method class 11Greedy method class 11
Greedy method class 11
Kumar
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 

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

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

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Recently uploaded (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

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