Set the distance to all vertexes to be ∞
Set the cost to s to be 0
while not finished
Select the vertex with the lowest cost not yet explored
If this vertex is f, stop
else update the costs to all vertexes adjacent to this one
Dijkstra(G,s,f)
- For each v in V do
- v.parent = null
- v.cost = ∞
- Q.insert(v)
- EndFor
- s.cost =0
- Q.DecreaseKey(s)
- While Q.size > 0 and f has not been selected
- u = Q.ExtractMin
- For each v i u.Adj()
- if v.cost > u.cost + weight(u,v)
- v.cost = u.cost + weight(u,v)
- Q.DecreaseKey(v)
- v.parent = u
- EndIf
- EndFor
- EndWhile