The Shortest Path
The shortest path problem aims to find the path between two vertices (or nodes) where the sum of the weights of each edge is minimized.
Floyd Algorithm
Implementation
Pseudocode
# let dist be a |V| × |V| array of minimum distances initialized to ∞ (infinity)
for each edge (u, v) do
dist[u][v] ← w(u, v) # The weight of the edge (u, v)
for each vertex v do
dist[v][v] ← 0
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 ifPath reconstruction pseudocode
Dijkstra's Algorithm
Pseudocode
Using a priority queue
Last updated