❖ Shortest Path |
Path = sequence of edges in graph G
cost(path) = sum of edge weights along path
Shortest path between vertices s and t
Applications: navigation, routing in data networks, …
❖ ... Shortest Path |
Some variations on shortest path (SP) ...
Source-target SP problem
Single-source SP problem
❖ Single-source Shortest Path (SSSP) |
Shortest paths from s to all other vertices
dist[]
pred[]
❖ Edge Relaxation |
Assume: dist[]
pred[]
dist[v]
dist[w]
Relaxation updates data for w if we find a shorter path from s to w :
dist[v]+weight < dist[w]
dist[w]←dist[v]+weight
pred[w]←v
❖ Dijkstra's Algorithm |
One approach to solving single-source shortest path …
dist[] // array of cost of shortest path from s pred[] // array of predecessor in shortest path from s vSet // vertices whose shortest path from s is unknown dijkstraSSSP(G,source): | Input graph G, source node | | initialise all dist[] to ∞ | dist[source]=0 | initialise all pred[] to -1 | vSet=all vertices of G | while vSet ≠ ∅ do | | find v ∈ vSet with minimum dist[v] | | for each (v,w,weight) ∈ edges(G) do | | relax along (v,w,weight) | | end for | | vSet=vSet \ {v} | end while
❖ Analysis of Dijkstra's Algorithm |
Why Dijkstra's algorithm is correct ...
Hypothesis:
(a) for visited s, dist[s] is shortest distance from source
(b) for unvisited t, dist[t] is shortest distance from source via visited nodes
Ultimately, all nodes are visited, so ...
❖ ... Analysis of Dijkstra's Algorithm |
Proof:
Base case: no visited nodes, dist[source]=0, dist[s]=∞ for all other nodes
Induction step:
❖ ... Analysis of Dijkstra's Algorithm |
Time complexity analysis …
Each edge needs to be considered once ⇒ O(E).
Outer loop has O(V) iterations.
Implementing "find s ∈ vSet with minimum dist[s]
s
vSet
Produced: 5 Jul 2020