Properties of Shortest Path 416 Corollary: Shortest paths are grown from shortest paths The length of shortest path s→pu→v is S(s, v)=8(s, m)+w(u, v) v<u,p>∈Eδ(s,v)≤δ(s,u)+w(u) Idea: Start With Upper bound 23 6 Initialize-Single-Source(G, s) 1. for each vertex vE v/G/ do dul π[v]←ML 4.ds7←0 O(v) ian williams, Spring 03
8 9 Properties of Shortest Path u v 1 10 9 0 2 3 4 6 s 7 5 5 7 2 x y Corollary: Shortest paths are grown from shortest paths. • The length of shortest path s ĺp u ĺ v is į(s,v) = į(s,u) + w(u,v). • <u,v> E į(s,v) į(s,u) + w(u,v) Brian Williams, Spring 03 11 Idea: Start With Upper Bound u v 1 10 9 2 3 4 6 s 0 7 5 2 x y Initialize-Single-Source(G, s) 1. for each vertex v V[G] 2. do d[u] ĸ 3. ʌ[v] ĸ NIL 4. d[s] ĸ 0 O(v) Brian Williams, Spring 03 12
Relax Bounds to shortest path Relax(u, v) Relax(u, v) 7 Relax(u, v, w) 1. if du]+w(u, v<dvI 2 dod/vy/←a]+ v7← Properties of relaxing bounds 2 2 Relax(u, v) Relax(u, v) (2 After calling Relax(u, v, w) d]+w(u,v)≥y d remains a shortest path upperbound after repeated calls Relax Once d[v] is the shortest path its value persists ian williams, Spring 03
Relax Bounds to Shortest Path u v u v 2 2 5 9 5 6 Relax(u, v) Relax(u, v) u v u v 2 2 5 7 5 6 Relax (u, v, w) 1. if d[u] + w(u,v) < d[v] 2. do d[v] ĸ d[u] + w(u,v) 3. ʌ[v] ĸ u Brian Williams, Spring 03 13 Properties of Relaxing Bounds u v u v 2 2 5 9 5 6 Relax(u, v) Relax(u, v) u v u v 2 2 5 9 5 6 After calling Relax(u, v, w) • d[u] + w(u,v) d[v] d remains a shortest path upperbound after repeated calls to Relax. Once d[v] is the shortest path its value persists Brian Williams, Spring 03 14
Dijkstras algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes y Q=s,u, v, x,yl Vertices to relax Vertices with shortest path value a williams, Spning 03 Dijkstras algorithm Assume all edges are non-negative Idea: Greedily relax out arcs of minimum cost nodes 46 Q=x,y, u, v) Vertices to relax Vertices with shortest path value ian williams, Spring 03
Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 9 0 2 3 4 6 s 7 5 2 x y Q = {s,u,v,x,y} Vertices to relax S = {} Vertices with shortest path value Brian Williams, Spring 03 15 Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 9 2 3 4 6 s 0 7 5 2 x y Q = {x,y,u,v} Vertices to relax S = {s} Vertices with shortest path value Brian Williams, Spring 03 16
Dijkstras algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes y Q=x,y, u, v! Vertices to relax s={s} Vertices with shortest path value Shortest path edge n[]=arrows Dijkstra's algorithm Assume all edges are non-negative Idea: Greedily relax out arcs of minimum cost nodes 10 46 0 Q=x,y, u, v) Vertices to relax Vertices with shortest path value Shortest path edge Ilvl=arrows ian williams, Spring 03
Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 10 9 0 2 3 4 6 s 7 5 2 x y Q = {x,y,u,v} Vertices to relax S = {s} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows Brian Williams, Spring 03 17 Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 10 9 2 3 4 6 s 0 7 5 5 2 x y Q = {x,y,u,v} Vertices to relax S = {s} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows Brian Williams, Spring 03 18
Dijkstras algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes y Q=x,y, u, v! Vertices to relax s={s} Vertices with shortest path valu Shortest path edge nlv=arrows Dijkstras algorithm Assume all edges are non-negative Idea: Greedily relax out arcs of minimum cost nodes 8 14 46 Q=y, u,\ Vertices to relax Vertices with shortest path value Shortest path edge Ilvl=arrows ian williams, Spring 03
Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 10 9 0 2 3 4 6 s 7 5 5 2 x y Q = {x,y,u,v} Vertices to relax S = {s} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows Brian Williams, Spring 03 19 Dijkstra’s Algorithm Assume all edges are non-negative. Idea: Greedily relax out arcs of minimum cost nodes u v 1 10 8 14 9 2 3 4 6 s 0 7 5 5 7 2 x y Q = {y,u,v} Vertices to relax S = {s, x} Vertices with shortest path value Shortest path edge Ȇ[v] = arrows Brian Williams, Spring 03 20