8 -1 Dynamic Programming. 8 -2 Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if i  2 Solved.

Slides:



Advertisements
Similar presentations
1 Appendix B: Solving TSP by Dynamic Programming Course: Algorithm Design and Analysis.
Advertisements

CS138A Single Source Shortest Paths Peter Schröder.
5-1 Chapter 5 Tree Searching Strategies. 5-2 Satisfiability problem Tree representation of 8 assignments. If there are n variables x 1, x 2, …,x n, then.
Chapter 7 Dynamic Programming.
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 3 The Greedy Method 3.
Computability and Complexity 23-1 Computability and Complexity Andrei Bulatov Search and Optimization.
Chapter 7 Dynamic Programming 7.
Branch and Bound Searching Strategies
§ 8 Dynamic Programming Fibonacci sequence
Dynamic Programming Technique. D.P.2 The term Dynamic Programming comes from Control Theory, not computer science. Programming refers to the use of tables.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Dynamic Programming Optimization Problems Dynamic Programming Paradigm
7 -1 Chapter 7 Dynamic Programming Fibonacci Sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
1 Branch and Bound Searching Strategies 2 Branch-and-bound strategy 2 mechanisms: A mechanism to generate branches A mechanism to generate a bound so.
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence (1) 0,1,1,2,3,5,8,13,21,34,... Leonardo Fibonacci ( ) 用來計算兔子的數量 每對每個月可以生產一對 兔子出生後,
The Traveling Salesperson Problem
1 Dynamic Programming 2012/11/20. P.2 Dynamic Programming (DP) Dynamic programming Dynamic programming is typically applied to optimization problems.
The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
MCS312: NP-completeness and Approximation Algorithms
Chapter 5 Dynamic Programming 2001 년 5 월 24 일 충북대학교 알고리즘연구실.
Graph Theory Topics to be covered:
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
Dynamic Programming Sequence of decisions. Problem state. Principle of optimality. Dynamic Programming Recurrence Equations. Solution of recurrence equations.
7 -1 Chapter 7 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
8 -1 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if i  2 Solved.
Contents of Chapter 5 Chapter 5 Dynamic Programming
6.1 Hamilton Circuits and Paths: Hamilton Circuits and Paths: Hamilton Path: Travels to each vertex once and only once… Hamilton Path: Travels to each.
Dynamic Programming: Manhattan Tourist Problem Lecture 17.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
8 -1 Chapter 8 Dynamic Programming Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if.
1 Branch and Bound Searching Strategies Updated: 12/27/2010.
Tuesday, April 30 Dynamic Programming – Recursion – Principle of Optimality Handouts: Lecture Notes.
1 Ch20. Dynamic Programming. 2 BIRD’S-EYE VIEW Dynamic programming The most difficult one of the five design methods Has its foundation in the principle.
Chapter 7 Dynamic Programming 7.1 Introduction 7.2 The Longest Common Subsequence Problem 7.3 Matrix Chain Multiplication 7.4 The dynamic Programming Paradigm.
Branch and Bound Searching Strategies
Lecture 2: Dynamic Programming 主講人 : 虞台文. Content What is Dynamic Programming? Matrix Chain-Products Sequence Alignments Knapsack Problem All-Pairs Shortest.
Dynamic Programming - DP December 18, 2014 Operation Research -RG 753.
Dynamic Programming Sequence of decisions. Problem state.
Lecture 5 Dynamic Programming
Shortest Path Problems
Shortest Path Problems
DYNAMIC PROGRAMMING.
CSCE350 Algorithms and Data Structure
Unit 3 (Part-I): Greedy Algorithms
Dynamic Programming Characterize the structure (problem state) of optimal solution Recursively define the value of optimal solution Compute the value of.
Unit-5 Dynamic Programming
Dynamic Programming General Idea
Unit 4: Dynamic Programming
Unit-4: Dynamic Programming
Shortest Path Problems
Dynamic Programming Characterize the structure (problem state) of optimal solution Recursively define the value of optimal solution Compute the value of.
Branch and Bound Searching Strategies
All pairs shortest path problem
Dynamic Programming General Idea
Single-Source All-Destinations Shortest Paths With Negative Costs
Shortest Path Problems
Dynamic Programming 動態規劃
Shortest Path Problems
Dynamic Programming Sequence of decisions. Problem state.
Advanced Analysis of Algorithms
Closures of Relations Epp, section 10.1,10.2 CS 202.
Dynamic Programming Sequence of decisions. Problem state.
Department of Computer Science & Engineering
Single-Source All-Destinations Shortest Paths With Negative Costs
All-Pairs Shortest Paths
Presentation transcript:

8 -1 Dynamic Programming

8 -2 Fibonacci sequence Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, … F i = i if i  1 F i = F i-1 + F i-2 if i  2 Solved by a recursive program: Much replicated computation is done. It should be solved by a simple loop.

8 -3 Dynamic Programming Dynamic Programming is an algorithm design method that can be used when the solution to a problem may be viewed as the result of a sequence of decisions

8 -4 The shortest path To find a shortest path in a multi-stage graph Apply the greedy method : the shortest path from S to T : = 8

8 -5 The shortest path in multistage graphs e.g. The greedy method can not be applied to this case: (S, A, D, T) = 23. The real shortest path is: (S, C, F, T) = 9.

8 -6 Dynamic programming approach Dynamic programming approach (forward approach): d(S, T) = min{1+d(A, T), 2+d(B, T), 5+d(C, T)} d(A,T) = min{4+d(D,T), 11+d(E,T)} = min{4+18, 11+13} = 22.

8 -7 Dynamic programming d(B, T) = min{9+d(D, T), 5+d(E, T), 16+d(F, T)} = min{9+18, 5+13, 16+2} = 18. d(C, T) = min{ 2+d(F, T) } = 2+2 = 4 d(S, T) = min{1+d(A, T), 2+d(B, T), 5+d(C, T)} = min{1+22, 2+18, 5+4} = 9. The above way of reasoning is called backward reasoning.

8 -8 Backward approach (forward reasoning) d(S, A) = 1 d(S, B) = 2 d(S, C) = 5 d(S,D)=min{d(S, A)+d(A, D),d(S, B)+d(B, D)} = min{ 1+4, 2+9 } = 5 d(S,E)=min{d(S, A)+d(A, E),d(S, B)+d(B, E)} = min{ 1+11, 2+5 } = 7 d(S,F)=min{d(S, A)+d(A, F),d(S, B)+d(B, F)} = min{ 2+16, 5+2 } = 7

8 -9 d(S,T) = min{d(S, D)+d(D, T),d(S,E)+ d(E,T), d(S, F)+d(F, T)} = min{ 5+18, 7+13, 7+2 } = 9

8 -10 Principle of optimality Principle of optimality: Suppose that in solving a problem, we have to make a sequence of decisions D 1, D 2, …, D n. If this sequence is optimal, then the last k decisions, 1  k  n must be optimal. e.g. the shortest path problem If i, i 1, i 2, …, j is a shortest path from i to j, then i 1, i 2, …, j must be a shortest path from i 1 to j In summary, if a problem can be described by a multistage graph, then it can be solved by dynamic programming.

8 -11 Forward approach and backward approach: Note that if the recurrence relations are formulated using the forward approach then the relations are solved backwards. i.e., beginning with the last decision On the other hand if the relations are formulated using the backward approach, they are solved forwards. To solve a problem by using dynamic programming: Find out the recurrence relations. Represent the problem by a multistage graph. Dynamic programming

8 -12 The resource allocation problem m resources, n projects profit p(i, j) : j resources are allocated to project i. maximize the total profit.

8 -13 The multistage graph solution The resource allocation problem can be described as a multistage graph. (i, j) : i resources allocated to projects 1, 2, …, j e.g. node H=(3, 2) : 3 resources allocated to projects 1, 2.

8 -14 Find the longest path from S to T : (S, C, H, L, T), =13 2 resources allocated to project 1. 1 resource allocated to project 2. 0 resource allocated to projects 3, 4.

8 -15 The traveling salesperson (TSP) problem e.g. a directed graph : Cost matrix:

8 -16 A multistage graph can describe all possible tours of a directed graph. Find the shortest path: (1, 4, 3, 2, 1) =17 The multistage graph solution

8 -17 The representation of a node Suppose that we have 6 vertices in the graph. We can combine {1, 2, 3, 4} and {1, 3, 2, 4} into one node. (3),(4,5,6) means that the last vertex visited is 3 and the remaining vertices to be visited are (4, 5, 6).

8 -18 The dynamic programming approach Let g(i, S) be the length of a shortest path starting at vertex i, going through all vertices in S and terminating at vertex 1. The length of an optimal tour : The general form: Time complexity: ( ),( ) (n-k)  (n-1)