Title: Lecture 5 Dynamic Programming
1Lecture 5 Dynamic Programming
2Dynamic Programming
Self-reducibility
3Divide 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.
4Dynamic Programming
- Divide the problem into subproblems.
- Conquer the subproblems by solving them
recursively. - Combine the solutions to subproblems into the
solution for original problem.
5Remark on Divide and Conquer
Key Point
Divide-and-Conquer is a DP-type technique.
6Greedy
Algorithms with Self-Reducibility
Dynamic Programming
Divide and Conquer
Local Ratio
7Matrix-chain Multiplication
8Fully Parenthesize
9Scalar Multiplications
10e.g.,
of scalar multiplications
11Step 1. Find recursive structure of
optimal solution
12Step 2. Build recursive formula about
optimal value
13Step 3. Computing optimal value
14Step 3. Computing optimal value
15Step 4. Constructing an optimal
solution
16151
15,125
11,875
10,500
9,375
7,125
5,375
7,875
4,375
2,500
3,500
15,700
2,625
750
1,000
5,000
0
0
0
0
0
0
17151
15,125
(3)
11,875
10,500
(3)
(3)
9,375
7,125
5,375
(3)
(3)
(3)
7,875
4,375
2,500
3,500
(3)
(3)
(5)
(1)
15,700
2,625
750
1,000
5,000
(5)
(4)
(3)
(2)
(1)
0
0
0
0
0
0
Optimal solution
18Running Time
19Running Time
How many recursive calls? How many mI,j will be
computed?
20 of Subproblems
21Running Time
22Remark on Running Time
- (1) Time for computing recursive formula.
- (2)The number of subproblems.
- (3) Multiplication of (1) and (2)
23Longest Common Subsequence
24Problem
25Recursive Formula
26More Examples
27A Rectangle with holes
NP-Hard!!!
28Guillotine cut
29Guillotine Partition
A sequence of guillotine cuts
Canonical one every cut passes a hole.
30Minimum length Guillotine Partition
- Given a rectangle with holes, partition it into
smaller rectangles without hole to minimize the
total length of guillotine cuts.
31Minimum Guillotine Partition
Dynamic programming In time O(n )
5
Each cut has at most 2n choices.
4
There are O(n ) subproblems.
Minimum guillotine partition can be a
polynomial-time approximation.
32What we learnt in this lecture?
- How to design dynamic programming.
- Two ways to implement.
- How to analyze running time.
33Puzzle