Lecture21 - Shortest Path Problem CSE 421 Algorithms...

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

View Full Document Right Arrow Icon
1 CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths 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 Shortest paths with a fixed number of edges • Find the shortest path from v to w with exactly k edges Express as a recurrence •Op t k (w) = min x [Opt k-1 (x) + c xw ] •Op t 0 (w) = 0 if v=w and infinity otherwise 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 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]))
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/25/2012 for the course CSE 421 taught by Professor Richardanderson during the Fall '06 term at University of Washington.

Page1 / 3

Lecture21 - Shortest Path Problem CSE 421 Algorithms...

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

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