Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic Programming Csc 487/687 Computing for Bioinformatics.

Similar presentations


Presentation on theme: "Dynamic Programming Csc 487/687 Computing for Bioinformatics."— Presentation transcript:

1 Dynamic Programming Csc 487/687 Computing for Bioinformatics

2 Subsequence A subsequence of a given sequence is just the given sequence with some elements (possible none) left out. A subsequence of a given sequence is just the given sequence with some elements (possible none) left out. Given a sequence X =, another sequence Z = is a subsequence of X if there exists a strictly increasing sequence of indices of X such that for all j=1,2,…,k, we have x ij = z j. Given a sequence X =, another sequence Z = is a subsequence of X if there exists a strictly increasing sequence of indices of X such that for all j=1,2,…,k, we have x ij = z j.

3 Common subsequence Given two sequences X and Y, we say that a sequence Z is a common subsequence of X and Y if Z is a subsequence of both X and Y. Given two sequences X and Y, we say that a sequence Z is a common subsequence of X and Y if Z is a subsequence of both X and Y. Longest-common-subsequence problem(LCS) Longest-common-subsequence problem(LCS) We are given two sequences X = and Y = and wish to find a maximum length common subsequence of X and Y.We are given two sequences X = and Y = and wish to find a maximum length common subsequence of X and Y.

4 How to solve it? Brute force search? Brute force search?

5 What is dynamic programming? Divide-and-conquer algorithms? Divide-and-conquer algorithms? Not independent? Subproblems share subsubproblems. Not independent? Subproblems share subsubproblems. Just once and then saves its answer in a table, thereby avoiding the work of recomputing the answer every time Just once and then saves its answer in a table, thereby avoiding the work of recomputing the answer every time

6 The development of a dynamic programming algorithm Characterize the structure of an optimal solution. Characterize the structure of an optimal solution. Recursively define the value of an optimal solution Recursively define the value of an optimal solution Compute the value of an optimal solution in bottom-up fashion Compute the value of an optimal solution in bottom-up fashion Construct an optimal solution from computed information Construct an optimal solution from computed information

7 Optimal-substructure property Given a sequence X =, we define the ith prefix of X, for i=0,1,…,m, as X i =. Given a sequence X =, we define the ith prefix of X, for i=0,1,…,m, as X i =. Optimal substructure of an LCS Optimal substructure of an LCS Let X =, Y = be sequences, and let Z = be any LCS of X and Y 1.If x m = y n, then z k = x m = y n and Z k-1 is an LCS of X m-1 and Y n-1 2.If x m ≠ y n, then z k ≠ x m implies Z is an LCS of X m-1 and Y. 3.If x m ≠ y n, then z k ≠ y n implies Z is an LCS of X and Y n-1.

8 The cost of optimal solution C [i, j] is the length of an LCS of the sequence X i and Y j. if either i=0 or j=0, one of the sequences has length of 0, so the LCS has length 0. the optimal substructure of the LCS problem gives the recursive formula C [i, j] is the length of an LCS of the sequence X i and Y j. if either i=0 or j=0, one of the sequences has length of 0, so the LCS has length 0. the optimal substructure of the LCS problem gives the recursive formula 0 if i=0 or j=0 0 if i=0 or j=0 c[i,j]= c[i-1, j-1]+1 if i,j>0 and x i =y j, max(c[i, j-1],c[i-1,j]) if i,j>0 and x i ≠ y j, max(c[i, j-1],c[i-1,j]) if i,j>0 and x i ≠ y j,

9 Example..


Download ppt "Dynamic Programming Csc 487/687 Computing for Bioinformatics."

Similar presentations


Ads by Google