You are on page 1of 13

Design and Analysis of Algorithms

Week 11 Lecture 18

Dr. Husnain Mansoor Ali


Recap
• What is good-suffix rule in Boyer-Moore
Design and Analysis of Algorithms

algorithm?
• What is Critical Path Method?
• What is Critical Path?
• How we identify Critical Path?
• What is multiple-source, multiple-sink maximum-
flow problem?
• What is supply demand problem?
2
All pairs shortest paths
• We can solve an all-pairs shortest-paths problem
Design and Analysis of Algorithms

by running a single-source shortest-paths


algorithm |V| times, once for each vertex as the
source.
• If all edge weights are nonnegative, we can use
Dijkstra’s algorithm.
• If the graph has negative-weight edges, we must
run the slower Bellman-Ford algorithm once
from each vertex.
3
Floyd-Warshall algorithm
• Problem
Design and Analysis of Algorithms

– Finding shortest paths between all pairs of vertices in


a graph

• Example
– This problem might arise in making a table of
distances between all pairs of cities for a road atlas.

4
Floyd-Warshall algorithm
• A dynamic-programming formulation to solve the
Design and Analysis of Algorithms

all-pairs shortest-paths problem

• Runs in θ(V^3) time 5


Floyd-Warshall algorithm
• Two matrices
Design and Analysis of Algorithms

– Matrix D of shortest path weights

– Predecessor matrix Π

6
Floyd-Warshall algorithm
• Creating predecessor matrix
Design and Analysis of Algorithms

• Updating predecessor matrix at each iteration

7
Design and Analysis of Algorithms
Floyd-Warshall algorithm

8
Design and Analysis of Algorithms
Floyd-Warshall algorithm

9
Sources used: Books
• Introduction to algorithms
Design and Analysis of Algorithms

– Thomas H. Cormen, Charles E. Leiserson, Ronald L.


Rivest, Clifford Stein

• Introduction to Algorithms
– Jon Kleinberg, Eva Tardos

• Algorithms
– S. Dasgupta, C. H. Papadimitriou, and U. V. Vazirani

10
Sources used: Books
• Algorithms and Data Structures
Design and Analysis of Algorithms

– Kurt Mehlhorn and Peter Sanders

• Analysis of Computer Algorithms


– Aho, Hopcroft, and Ullman

• Art of Computer Programming


– Donald E. Knuth

11
Sources used: Online Links
• Algorithms: Design and Analysis, Part 1
Design and Analysis of Algorithms

– https://www.coursera.org/course/algo
• Algorithms: Design and Analysis, Part 2
– https://www.coursera.org/course/algo2
• Lecture Slides for Algorithm Design
– http://www.cs.princeton.edu/~wayne/kleinberg-
tardos/
• Course Notes - CS 161 - Design and Analysis of
Algorithms
– http://www.ics.uci.edu/~goodrich/teach/cs161/note
s/ 12
Design and Analysis of Algorithms
Sources used:

13

You might also like