Lecture21 - CSE 421 Algorithms Richard Anderson Lecture 21...

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

CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths

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

View Full Document
Shortest Path Problem Dijkstra’s Single Source Shortest Paths Algorithm O(mlog n) time, positive cost edges General case – handling negative edges If there exists a negative cost cycle, the shortest path is not defined Bellman-Ford Algorithm O(mn) time for graphs with negative cost edges
Lemma If a graph has no negative cost cycles, then the shortest paths are simple paths Shortest paths have at most n-1 edges

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

View Full Document
Shortest paths with a fixed number of edges Find the shortest path from v to w with exactly k edges
Express as a recurrence Opt k (w) = min x [Opt k-1 (x) + c xw ] • Opt 0 (w) = 0 if v=w and infinity otherwise

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

View Full Document
Algorithm, Version 1 foreach w M[0, w] = infinity; M[0, v] = 0; for i = 1 to n-1 foreach w M[i, w] = min x (M[i-1,x] + cost[x,w]);
Algorithm, Version 2 foreach w M[0, w] = infinity; M[0, v] = 0; for i = 1 to n-1 foreach w M[i, w] = min(M[i-1, w], min x (M[i-1,x] + cost[x,w]))

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 13

Lecture21 - CSE 421 Algorithms Richard Anderson Lecture 21...

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

View Full Document
Ask a homework question - tutors are online