dynamic programming (longest common subsequence)
DESCRIPTION
Dynamic Programming (Longest Common Subsequence). Subsequence. String Z is a subsequence of string X if Z’s characters appear in X following the same left-to-right order. X = < A, B, C, T, D, G, N, A, B > Z = < B, D, A >. Longest Common Subsequence (LCS). - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/1.jpg)
Dynamic Programming(Longest Common Subsequence)
![Page 2: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/2.jpg)
Subsequence
• String Z is a subsequence of string X if Z’s characters appear in X following the same left-to-right order
X = < A, B, C, T, D, G, N, A, B >
Z = < B, D, A >
![Page 3: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/3.jpg)
Longest Common Subsequence (LCS)
• String Z is a common subsequence of strings X and Y if Z’s characters appear in both X & Y following the same left-to-right order
X = < A, B, C, T, B, D, A, B >Y = < B, D, C, A, B, A >
• < B, C, A > is a common subsequence of both X and Y.
• < B, C, B, A > or < B, C, A, B > is the Longest Common Subsequence (LCS) of X and Y.
LCS is used to measure the similarity between two strings X and Y. The longer the LCS , the more similar X and Y
![Page 4: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/4.jpg)
LCS Problem Definition
• We are given two sequences – X = <x1,x2,...,xm>, and
– Y = <y1,y2,...,yn>
• We need to find the LCS between X and Y
Very common in DNA sequences
![Page 5: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/5.jpg)
Characterization of LCS
![Page 6: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/6.jpg)
Characterization of LCS (Cont’d)
![Page 7: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/7.jpg)
Recursive Nature of LCS
• Implications of Theorem 15.1
![Page 8: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/8.jpg)
Recursive Equation
• Input X = <x1, x2, …., xm>
Y = <y1, y2, ………, yn>
• Assume C[i, j] is the LCS for the first i positions in X with the first j positions in Y– C[i,j] = LCS(<x1, x2, …., xi>, <y1, y2, ………, yj>)
Our goal is to compute C[m,n]
![Page 9: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/9.jpg)
Dynamic Programming for LCS
Initialization step
![Page 10: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/10.jpg)
Dynamic Programming for LCS
If matching, go diagonal
![Page 11: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/11.jpg)
Dynamic Programming for LCS
Else select the larger of top or left
![Page 12: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/12.jpg)
Dynamic Programming for LCS
Note that array c keeps track of the cost,Array b keeps track of the parent (to backtrack)
![Page 13: Dynamic Programming (Longest Common Subsequence)](https://reader035.vdocuments.site/reader035/viewer/2022062221/56814558550346895db229c6/html5/thumbnails/13.jpg)
Summary of the Main Strategies