280 likes | 505 Views
Design and Analysis of Algorithms - Chapter 8. 2. Giving credit where credit is due:Most of the lecture notes are based on the slides from the Textbook's companion website http://www.aw-bc.com/info/levitinSome of the notes are based on slides created by Dr. Philippe Laborie, ILOG and Mark Llewe
E N D
1. Design and Analysis of Algorithms - Chapter 8 1 CSCE 310: Data Structures & Algorithms
2. Design and Analysis of Algorithms - Chapter 8 2 Giving credit where credit is due:
Most of the lecture notes are based on the slides from the Textbook’s companion website
http://www.aw-bc.com/info/levitin
Some of the notes are based on slides created by Dr. Philippe Laborie, ILOG and Mark Llewellyn, University of Central Florida.
I have modified many of their slides and added new slides.
CSCE 310: Data Structures & Algorithms
3. Design and Analysis of Algorithms - Chapter 8 3 Examples of dynamic programming algorithms
4. Design and Analysis of Algorithms - Chapter 8 4 Warshall’s algorithm: transitive closure
5. Design and Analysis of Algorithms - Chapter 8 5 Warshall’s algorithm
6. Design and Analysis of Algorithms - Chapter 8 6 Warshall’s algorithm
7. Design and Analysis of Algorithms - Chapter 8 7 Warshall’s algorithm
8. Design and Analysis of Algorithms - Chapter 8 8 Warshall’s algorithm
9. Design and Analysis of Algorithms - Chapter 8 9 Warshall’s algorithm
10. Design and Analysis of Algorithms - Chapter 8 10 Warshall’s algorithm
11. Design and Analysis of Algorithms - Chapter 8 11 Warshall’s algorithm
12. Design and Analysis of Algorithms - Chapter 8 12 Warshall’s algorithm
13. Design and Analysis of Algorithms - Chapter 8 13 In-class exercises 8.2.1
Apply Warshall’s algorithm to find the transitive closure of the digraph defined by the following adjacency matrix
14. In-class exercises Problem 2
a. What is the time efficiency of Warshall’s algorithm?
Design and Analysis of Algorithms - Chapter 8 14
15. In-class exercises Problem 2
a. What is the time efficiency of Warshall’s algorithm?
b. How to solve this “finding all paths in a directed graph” problem by a traversal-based algorithm (BFS-based or DFS-based)?
Design and Analysis of Algorithms - Chapter 8 15
16. In-class exercises Problem 2
a. What is the time efficiency of Warshall’s algorithm?
b. How to solve this “finding all paths in a directed graph” problem by a traversal-based algorithm (BFS-based or DFS-based)?
c. Explain why the time efficiency of Warshall’s algorithm is inferior to that of traversal-based algorithm for sparse graphs represented by their adjacency lists.
Design and Analysis of Algorithms - Chapter 8 16
17. Design and Analysis of Algorithms - Chapter 8 17 Floyd’s algorithm: all pairs shortest paths
18. Design and Analysis of Algorithms - Chapter 8 18 Floyd’s algorithm: all pairs shortest paths
19. Design and Analysis of Algorithms - Chapter 8 19 Floyd’s algorithm: all pairs shortest paths
20. Design and Analysis of Algorithms - Chapter 8 20 Floyd’s algorithm: all pairs shortest paths
21. Design and Analysis of Algorithms - Chapter 8 21 Floyd’s algorithm: all pairs shortest paths
22. Design and Analysis of Algorithms - Chapter 8 22 Floyd’s algorithm: all pairs shortest paths
23. Design and Analysis of Algorithms - Chapter 8 23 In-Class Exercises Apply the Floyd’s algorithm to the following problem instance:
D(0) =
24. Enhanced Floyd’s Algorithm
25. Design and Analysis of Algorithms - Chapter 8 25 In-Class Exercises Apply the enhanced Floyd’s algorithm, which finds the shortest paths and their lengths, to the following problem instance:
D(0) =
26. Dynamic programming Dynamic programming is a technique for solving problems with overlapping subproblems. It suggests solving each smaller subproblem once and recording the results in a table from which a solution to the original problem can be then obtained. Design and Analysis of Algorithms - Chapter 8 26
27. Dynamic programming Dynamic programming is a technique for solving problems with overlapping subproblems. It suggests solving each smaller subproblem once and recording the results in a table from which a solution to the original problem can be then obtained.
What are the overlapping subproblems in Floyd’s algorithm? Design and Analysis of Algorithms - Chapter 8 27
28. Principle of Optimality General principle that underlines dynamic programming algorithms for optimization problems:
Principle of optimality: an optimal solution to any instance of an optimization problem is composed of optimal solutions to its subinstances.
The principle of optimality holds in most cases. (A rare example: it fails for finding longest simple paths).
29. 29 In-Class Exercises Index: 0 1 2 … i-1 i i+1 … n
aj aj+1 aj+2 … an a0 a1 ... aj-1
where a0 < a1 < a2 < a3 < … < an
How to find out the corresponding index i for a0?
Given an array a0 a1 ... an-1, where a0 < a1 < a2 < a3 < … < an-1 , design an efficient algorithm to tell if there are three items in the array such that ax + ay = az , what is the time efficiency of your algorithm?