Author: Hayden Smith 2021
Why?
What?
We're going to search for the shortest path between two vertices on a weighted graph with non-negative weights.
....Pretty much just a BFS with weighted edges....
Shortest paths from s to all other vertices:
Edge relaxation occurs whilst we are exploring a graph for the shortest path. This is because dist[] and pred[] show the shortest path so far.
If we have:
Relaxation updates data for w if we find a shorter path from s to w :
dijkstraSSSP(G,source):
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
initialise all dist[] to ∞
dist[source]=0
initialise all pred[] to -1
vSet = all vertices of G
while vSet is not empty:
find v in vSet with minimum dist[v]
for each (v,w,weight) in edges(G):
relax along (v,w,weight)
vSet = vSet \ {v}
Each edge needs to be considered once ⇒ O(E).
Outer loop has O(V) iterations.
Implementing "find s ∈ vSet with minimum dist[s]"