N | set of nodes |
N' | set of 'visited' nodes |
c(u,v) | link cost u→v, possibly ∞ |
D(u,v) | path cost u→v |
P(u,v) | 2nd-last hop on path from u→v |
N' = { u } D(u,v) = c(u,v) for all neighbours v of u loop: find w not in N' with minimum D(u,w) add w to N' for all v not in N' and adjacent to w: if (D(u,w) + c(w,v) < D(u,v)): D(u,v) = D(u,w) + c(w,v) P(u,v) = w until N' == N