Shortest Path
Dijkstraβs algorithm
Procedure DIJKSTRA(G, s)
Inputs:
* G: a directed graph containing a set V of n vertices and a set E of m
directed edges with nonnegative weights.
* s: a source vertex in V.
Result: For each non-source vertex v in V, shortest[v] is the weight sp(s, v)
of a shortest path from s to v and pred[v] is the vertex preceding v
on some shortest path. For the source vertex s, shortest[s] = 0 and
pred[s] = NULL. If there is no path from s to v, then shortest[v] = β
and pred[v] = NULL.
1. Set shortest[v] to β for each vertex v except s, set shortest[s] to 0,
and set pred[v] to NULL for each vertex v.
2. Set Q to contain all vertices.
3. While Q is not empty, do the following:
A. Find the vertex u in set Q with the lowest shortest value and
remove it from Q.
B. For each vertex v adjacent to u:
i. Call RELAX(u, v).
Simple array implementation
Binary heap implementation

The Bellman-Ford algorithm
The Floyd-Warshall algorithm
Last updated