Expand description
Single-source shortest paths: Dijkstra, Bellman-Ford and A*.
See the book entry Shortest paths.
Structs§
- Shortest
Paths - Distances from a source and the predecessor tree for path reconstruction.
Functions§
- a_star
- A* search from
sourcetotargetguided byheuristic(v), an estimate of the remaining cost. With an admissible (never overestimating) and consistent heuristic the returned path is optimal; a zero heuristic reduces to Dijkstra. Returns(cost, path)orNoneif unreachable. - bellman_
ford - The Bellman-Ford algorithm,
O(V E), allowing negative weights. Returns an error if a negative cycle is reachable from the source (shortest paths are then undefined). - dijkstra
- Dijkstra’s algorithm with a binary heap,
O((V + E) log V). Edge weights must be non-negative.