# module6 - Dynamic programming techniques Topics Basics of...

This preview shows pages 1–9. Sign up to view the full content.

9/23/09 CSE 5311 Fall 2009 M Kumar 1 Dynamic programming techniques Topics Basics of DP Longest Common subsequence 0-1 Knapsack problem Matrix-chain Multiplication All-pairs Shortest paths Further Reading Chapter 6 Textbook

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
9/23/09 CSE 5311 Fall 2009 M Kumar 2 Dynamic programming Solves problems by combining the solutions to subproblems DP is applicable when subproblems are not independent Subproblems share subsubproblems In such cases a simple Divide and Conquer strategy solves common subsubproblems . In DP every subproblem is solved just once and the solution is saved in a table for future reference (avoids re-computation). DP is typically applied to optimization problems A given problem may have many solutions, DP chooses the optimal solution.
9/23/09 CSE 5311 Fall 2009 M Kumar 3 Four stages of Dynamic Programming Characterize the structure of an optimal solution Recursively define the value of an optimal solution Compute the value of an optimal solution in a bottom-up fashion Construct an optimal solution from computed results

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
9/23/09 CSE 5311 Fall 2009 M Kumar 4 Longest common subsequence A subsequence is formed from a list by deleting zero or more elements (the remaining elements are in order) A common subsequence of two lists is a subsequence of both. The longest common subsequence (LCS) of two lists is the longest among the common subsequences of the two lists. Example: abcabba and cbabac are two sequences baba is a subsequence in both a b c ab b a and c baba c
9/23/09 CSE 5311 Fall 2009 M Kumar 5 a b c a b b a b a b a c b a b a c

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
9/23/09 CSE 5311 Fall 2009 M Kumar 6 To find the length of an LCS of lists x and y, we need to find the lengths of the LCSs of all pairs of prefixes. a prefix is an initial sublist of a list If x = ( a 1 ,a 2 ,a 3 , . . ., a m ) and y = ( b 1 ,b 2 ,b 3 , . . ., b n ) 0 i m and 0 j n Consider an LCS of the prefix ( a 1 ,a 2 ,a 3 , . . ., a i ) from x and of the prefix ( b 1 ,b 2 ,b 3 , . . ., b j ) from y. If i or j = 0 then one of the prefixes is ε and the only possible common subsequence between x and y is and the length of the LCS is zero.
9/23/09 CSE 5311 Fall 2009 M Kumar 7 L(i,j ) is the length of the LCS of ( a 1 ,a 2 ,a 3 , . . ., a i ) and ( b 1 ,b 2 ,b 3 , . . ., b j ). e.g., a 1 a 2 a 3 a 4 a 5 a 6 a 7 (i=7) b 1 b 2 b 3 b 4 b 5 b 6 (j=6) suppose a 2 =b 1 ; a 4 =b 2 ; a 5 =b 4 ; a 7 =b 6 . L(7,6) = 4 BASIS: If i+j = 0, then both i and j are zero and so the LCS is ε . INDUCTION: Consider i and j , and suppose we have already computed L( g,h ) for any g and h such that g+h < i+j . 1. If either i or j is 0 then L (i,j) = 0. 2. If i >0 and j >0, and a i b j then L ( i,j ) = max( L ( i,j-1 ), L ( i-1,j )). 3. If i >0 and j > 0, and a i = b j then L ( i,j ) = L ( i-1,j-1 )+1.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
9/23/09 CSE 5311 Fall 2009 M Kumar 8 ε a b c a ε c b 0 0 0 0 0 0 1 1 1 1 1.If either i or j is 0 then L (i,j) = 0. 2.If i >0 and j >0, and a i b j then L ( i,j ) = max( L ( i,j-1 ), L ( i-1,j )).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 34

module6 - Dynamic programming techniques Topics Basics of...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online