1 / 41

Lecture 5 Dynamic Programming

This lecture discusses the concept of dynamic programming using the divide and conquer technique, explaining how to divide a problem into subproblems, solve them recursively, and combine the solutions. It also covers self-reducibility and algorithms with self-reducibility. The lecture concludes with examples and analysis of running time.

jjacques
Download Presentation

Lecture 5 Dynamic Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 5 Dynamic Programming

  2. 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.

  3. Quiz Sample • True or false? • Every algorithm that contains a divide step and a conquer step is a divide-and-conquer algorithm.

  4. Quiz Sample • True or false? • Every algorithm that contains a divide step and a conquer step is a divide-and-conquer algorithm. • Answer: No • A dynamic programming contains a divide step and a conquer step and may not be a divide-and-conquer algorithm.

  5. Dynamic Programming Self-reducibility Self-reduction may not have tree structure

  6. 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.

  7. Remark on Divide and Conquer Key Point: Divide-and-Conquer is a DP-type technique.

  8. Algorithms with Self-reducibility Algorithms with Self-Reducibility Dynamic Programming Divide and Conquer Greedy Local Ratio

  9. Matrix-chain Multiplication

  10. Fully Parenthesize

  11. Scalar Multiplications

  12. e.g., # of scalar multiplications

  13. Step 1. Find recursive structure of optimal solution

  14. Step 2. Build recursive formula about optimal value

  15. Step 3. Computing optimal value

  16. Step 3. Computing optimal value

  17. Step 4. Constructing an optimalsolution

  18. 151 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

  19. 151 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 (1) (3) (3) (5) 15,700 2,625 750 1,000 5,000 (1) (2) (3) (4) (5) 0 0 0 0 0 0 Optimal solution

  20. Running Time

  21. Running Time How many recursive calls? How many m[I,j] will be computed?

  22. # of Subproblems

  23. Running Time

  24. Remark on Running Time (1) Time for computing recursive formula. (2)The number of subproblems. (3) Multiplication of (1) and (2)

  25. Longest Common Subsequence

  26. Problem 10110110 00100100

  27. Recursive Formula

  28. Related Problem 10110110 00100100

  29. Recursive Formula

  30. Recursive Formula

  31. Related Problem 10110110 00100110

  32. More Examples

  33. A Rectangle with holes NP-Hard!!!

  34. Guillotine cut

  35. Guillotine Partition A sequence of guillotine cuts Canonical one: every cut passes a hole.

  36. Minimum length Guillotine Partition • Given a rectangle with holes, partition it into smaller rectangles without hole to minimize the total length of guillotine cuts.

  37. Minimum 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.

  38. What we learnt in this lecture? • How to design dynamic programming. • Two ways to implement. • How to analyze running time.

  39. Quiz Sample • True or False • Analysis method for dynamic programming can also be applied to divide-and-conquer algorithms. • Answer: True

  40. Quiz Sample • True or False • Every dynamic programming can be analyzed with formula: Run-time = (table size) x (computation time of recursive formula). • Answer: False • A counterexample can be seen in study of the shortest path problem.

  41. Puzzle

More Related