Module_6 - Dynamic programming techniques Topics Basics of...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
11/19/09 CSE 5311 Spring 2007 M Kumar 1 Dynamic programming techniques Topics Basics of DP Matrix-chain Multiplication Longest Common subsequence All-pairs Shortest paths Further Reading Chapter 6 Textbook
Background image of page 1

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

View Full DocumentRight Arrow Icon
11/19/09 CSE 5311 Spring 2007 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.
Background image of page 2
11/19/09 CSE 5311 Spring 2007 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
11/19/09 CSE 5311 Spring 2007 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 of both
Background image of page 4
11/19/09 CSE 5311 Spring 2007 M Kumar 5 a b c a b b a b a b a c b a b a c
Background image of page 5

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

View Full DocumentRight Arrow Icon
11/19/09 CSE 5311 Spring 2007 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.
Background image of page 6
11/19/09 CSE 5311 Spring 2007 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 ). 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.
Background image of page 7

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

View Full DocumentRight Arrow Icon
11/19/09 CSE 5311 Spring 2007 M Kumar 8 ε a b c a ε 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 bj 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 . 0 1 1 2 2
Background image of page 8
11/19/09 CSE 5311 Spring 2007 M Kumar 9 Procedure LCS( x,y ) Input : The lists x and y Output : The longest common subsequence and its length 1. for j 0 to n do 2. L[0,j] 0; 3. for i 1 to m do 4. L[i,0] 0; 5. for j 1 to n do 6. if a[i] b[j] then 7. L[i,j] max {L[i-1,j],L[i,j-1]}; 8. else 9 L[i,j] 1+L[i-1,j-1];
Background image of page 9

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

View Full DocumentRight Arrow Icon
11/19/09 CSE 5311 Spring 2007 M Kumar 10 Example:
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/18/2009.

Page1 / 32

Module_6 - Dynamic programming techniques Topics Basics of...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online