Design and Analysis of Algorithms Week 11 Lecture 19: Dr. Husnain Mansoor Ali
Design and Analysis of Algorithms Week 11 Lecture 19: Dr. Husnain Mansoor Ali
Week 11 Lecture 19
algorithm?
• What is the type of Floyd-Warshall algorithm?
• What is predecessor matrix?
• Differentiate between single-source shortest
path and all-pair shortest path algorithms
2
Reminder!
• Quiz 2 next week
Design and Analysis of Algorithms
– Wednesday / Thursday
3
Shortest Paths
• The problem: Given a source vertex s, find the
Design and Analysis of Algorithms
– Distance table:
• distances from source vertex
5
Shortest Paths: Dijkstra
• Take a vertex and examine all adjacent vertices
Design and Analysis of Algorithms
6
Shortest Paths: Dijkstra
• Distance is not any more the number of edges,
Design and Analysis of Algorithms
7
Design and Analysis of Algorithms
Pseudocode
8
Design and Analysis of Algorithms
Pseudocode
9
Design and Analysis of Algorithms
10
Design and Analysis of Algorithms
11
Design and Analysis of Algorithms
12
Design and Analysis of Algorithms
13
Design and Analysis of Algorithms
14
Design and Analysis of Algorithms
15
Design and Analysis of Algorithms
16
Shortest Paths:
Dijkstra Time Complexity
• Each vertex is stored only once in the queue
Design and Analysis of Algorithms
– O(V)
• DeleteMin operation is
– O( V logV )
• Updating the priority queue
– search and insert: O(log V)
• Performed at most for each edge
– O(E logV)
18
Design and Analysis of Algorithms
Relaxation
19
Apply Dijkstra Shortest Path Algo.
Design and Analysis of Algorithms
20
Bellman-ford algorithm
Design and Analysis of Algorithms
22
Design and Analysis of Algorithms
Bellman-ford algorithm
23
Design and Analysis of Algorithms
Bellman-ford algorithm
24
Design and Analysis of Algorithms
Floyd-Warshall algorithm
25
Sources used: Books
• Introduction to algorithms
Design and Analysis of Algorithms
• Introduction to Algorithms
– Jon Kleinberg, Eva Tardos
• Algorithms
– S. Dasgupta, C. H. Papadimitriou, and U. V. Vazirani
26
Sources used: Books
• Algorithms and Data Structures
Design and Analysis of Algorithms
27
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/ 28
Design and Analysis of Algorithms
Sources used:
29