Lecture 5 Dynamic Programming
Dynamic Programming Self-reducibility
Divide and Conquer Divide the problem into subproblems. Conquer the subproblems by solving them recursively. Combine the solutions to subproblems into the solution for original problem.
Dynamic Programming Divide the problem into subproblems. Conquer the subproblems by solving them recursively. Combine the solutions to subproblems into the solution for original problem.
Remark on Divide and Conquer Key Point: Divide-and-Conquer is a DP-type technique.
Algorithms with Self-Reducibility Dynamic Programming Divide and Conquer Greedy Local Ratio
Matrix-chain Multiplication
Fully Parenthesize
Scalar Multiplications
# of scalar multiplications e.g.,
Step 1. Find recursive structure of optimal solution
Step 2. Build recursive formula about optimal value
Step 3. Computing optimal value
Step 4. Constructing an optimal solution
,125 11,87510,500 9,3757,1255,375 7,8754,3752,5003,500 15,7002, ,0005,
,125 11,87510,500 9,3757,1255,375 7,8754,3752,5003,500 15,7002, ,0005, (3) (5) (4)(3)(2) (1) Optimal solution
Running Time
How many recursive calls? How many m[I,j] will be computed?
# of Subproblems
Running Time
Remark on Running Time (1) Time for computing recursive formula. (2)The number of subproblems. (3) Multiplication of (1) and (2)
Longest Common Subsequence
Problem
Recursive Formula
More Examples
A Rectangle with holes NP-Hard!!!
Guillotine cut
Guillotine Partition A sequence of guillotine cuts Canonical one: every cut passes a hole.
Minimum length Guillotine Partition Given a rectangle with holes, partition it into smaller rectangles without hole to minimize the total length of guillotine cuts.
Minimum Guillotine Partition Dynamic programming In time O(n ): 5 Each cut has at most 2n choices. There are O(n ) subproblems. 4 Minimum guillotine partition can be a polynomial-time approximation.
What we learnt in this lecture? How to design dynamic programming. Two ways to implement. How to analyze running time.
Puzzle