This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1 Weighted Graph Algorithms. • Weighted Shortest Path Problems Dijkstra’s algorithm • All Pairs Shortest Path Warshall’s algorithm • Minimum spanning trees Prim’s algorithm 2 Been there, done that! 3 ShortestPath in Weighted Graphs • Weight w(i, j) associated with each edge (v i , v j ). – [sometimes you’ll see c(i,j)] • The cost of a path v 1 v 2 ..v n is • Find the shortest weighted path from s to every other vertex in G. – Single Source Shortest Path 1 = + 1 1 ) 1 , ( n i i i w 4 ShortestPath Problem Solutions • Unweighted – Breadth First Search • Nonnegative Weights – Dijkstra’s Algorithm • Negative weights with no negative cycles – BellmanFord Algorithm • Negative cycles – No solution 5 Dijkstra’s Algorithm Dijkstra (G, v) foreach x ∈ V x.dist ← ∞ ; Initially all nodes infinite distance x.p ← nil ; and no known parent x.known ← false Q.insert(x) ; Insert into priority queue by dist Q.decreasekey(v, 0) ; Zero distance to first vertex while Q not empty v ← Q.deletemin() ; Vertex at minimum distance v.known = true foreach x such that (v,x) ∈ E and !x.known if v.dist + w(v,x) < x.dist then Q.decreasekey(x, v.dist + w(v,x) ) x.p ← v 6 Example v 3 2 v 6 v 5 v 4 v 2 v 7 4 10 1 3 2 5 8 1 4 2 6 v d v v 1 v 2 ∞ v 3 ∞ v 4 ∞ v 5 ∞ v 6 ∞ v 7 ∞ Initialization Priority Queue v 7 Example v d v v 4 1 v 2 2 v 3 ∞ v 5 ∞ v 6 ∞ v 7 ∞ Priority Queue Process v 1 v 3 2 v 6 v 5 v v v v 7 4 10 1 3 2 5 8 1 4 2 6 2 1 8 Example v d v v 2 2 v 3 3 v 5 3 v 7 5 v 6 9 Priority Queue Process v 4 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 2 1 3 3 5 9 9 Example v d v v 3 3 v 5 3 v 7 5 v 6 9 Priority Queue Process v 2 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 2 1 3 3 5 9 V 4 already known V 5 not shorter 10 Example v d v v 5 3 v 7 5 v 6 8 Priority Queue Process v 3 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 2 1 3 3 5 8 V 1 already known V 6 shorter 11 Example v d v v 7 5 v 6 8 Priority Queue Process v 5 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 2 1 3 3 5 8 V 7 not shorter 12 Example v d v v 6 6 Priority Queue Process v 7 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 2 1 3 3 5 6 V 6 shorter 13 Example v d v Priority Queue Process v 6 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 2 1 3 3 5 6 We be done! 14 Dijkstra’s Algorithm Dijkstra (G, v) foreach x...
View
Full
Document
This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.
 Spring '08
 M.McCullen
 Algorithms, Data Structures

Click to edit the document details