lec40a - Lecture 40 All Pairs Shortest Paths 20.2.3...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 40 All Pairs Shortest Paths 20.2.3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
All-Pairs Shortest Paths Given an n vertex directed weighted graph, find a shortest path from vertex i to vertex j for each for the n 2 vertex pairs (i,j) . 1 2 3 4 5 6 7 5 7 1 7 9 1 9 4 4 5 16 4 2 8 1 2
Background image of page 2
Dijkstra’s Single Source Algorithm Use Dijkstra’s algorithm n times, once with each of the n vertices as the source vertex. 1 2 3 4 5 6 7 5 7 1 7 9 1 9 4 4 5 16 4 2 8 1 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Performance Time complexity is O(n 3 ) time. Works only when no edge has a cost < 0 .
Background image of page 4
Dynamic Programming Solution Time complexity is Θ (n 3 ) time. Works so long as there is no cycle whose length is < 0 . When there is a cycle whose length is < 0 , some shortest paths aren’t finite. If vertex 1 is on a cycle whose length is -2 , each time you go around this cycle once you get a 1 to 1 path that is 2 units shorter than the previous one. Simpler to code, smaller overheads. Known as Floyd’s shortest paths algorithm.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Decision Sequence First decide the highest intermediate vertex (i.e., largest vertex number) on the shortest path from i to j . If the shortest path is i, 2, 6, 3, 8 , 5, 7, j the first decision is that vertex 8 is an intermediate vertex on the shortest path and no intermediate vertex is larger than 8 . Then decide the highest intermediate vertex on the path from i to 8 , and so on. i j
Background image of page 6
Problem State (i,j,k) denotes the problem of finding the shortest path from vertex i to vertex j that has no intermediate vertex larger than k . (i,j,n) denotes the problem of finding the shortest path from vertex i to vertex j (with no restrictions on intermediate vertices).
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 31

lec40a - Lecture 40 All Pairs Shortest Paths 20.2.3...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online