The shortest path from one vertex to the rest.
Steps:
S={v}
, and the distance from vertex v to itself is 0. U contains vertices other than v, and the distance from v to vertices i in U is the weight on the edge.Di,j,k is the shortest path from i to j only passing verticles (1..k).
for each vertex v
dist[v][v] ← 0
for each edge (u,v)
dist[u][v] ← w(u,v) // the weight of the edge (u,v)
for k from 1 to |V|
for i from 1 to |V|
for j from 1 to |V|
if dist[i][j] > dist[i][k] + dist[k][j]
dist[i][j] ← dist[i][k] + dist[k][j]
end if