L18-shortestPaths

With non negative weights and source s dijkstrag s

This preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: ) 8 for each v ⇤ Adj (u) 9 do if dv > du + w(u, v ) 10 then dv du + w(u, v ) 11 ⇥v u 12 decreasekey(Q, v ) prim(G = (V, E )) 1Q ⇧ Q is a Priority Queue 2 Initialize each v ⇤ V with key kv ⇥, v nil 3 Pick a starting node r and set kr 0 4 Insert all nodes into Q with key kv . 5 while Q ⌅= ⇧ 6 do u extract-min(Q) 7 for each v ⇤ Adj (u) 8 do if v ⇤ Q and w(u, v ) < kv 9 then v u 10 decrease-key(Q, v, w(u, v )) Theorem 4 Given any weighted, directed graph G = (V, E ) with non-negative weights and source s, dijkstra(G, s) terminates with du = (s, v ) for all v ⇤ V . Sets kv w(u, v ) 3 L19 running time Dijkstra(G = (V, E ), s) 1 for all v ⇤ V 2 do du ⇥ 3 ⇥u nil 4 ds 0 5Q makequeue(V ) use du as key 6 while Q ⌅= ⇧ 7 do u extractmin(Q) 8 for each v ⇤ Adj (u) 9 do if dv > du + w(u, v ) 10 then dv du + w(u, v ) 11 ⇥v u 12 decreasekey(Q, v ) Theorem 4 Given any weighted, directed graph G = (V, E ) with non-negative weights and source s, dijkstra(G, s) terminates with du = (s, v ) for all v ⇤ V . why does dijkstra work? triangle inequality: upper bound: ⇤(u, v) ⇥ E, (s, v) dv (s, v) (s, u) + w(u, v) breadth first search input: output: dv = (s, v ) smallest # of edges fr...
View Full Document

This note was uploaded on 02/25/2014 for the course CS 4102 taught by Professor Horton during the Spring '10 term at UVA.

Ask a homework question - tutors are online