|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Johnson's algorithm for all-pairs shortest paths. More...
#include <Dijkstra.H>#include <Bellman_Ford.H>#include <tpl_graph.H>#include <tpl_dynList.H>#include <ah-errors.H>#include <limits>#include <type_traits>Go to the source code of this file.
Classes | |
| class | Aleph::Johnson< GT, Distance, Ait, NAit, SA > |
| Johnson's algorithm for all-pairs shortest paths. More... | |
| struct | Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Reweighted_Dist |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
Johnson's algorithm for all-pairs shortest paths.
Implements Johnson's algorithm combining Bellman-Ford and Dijkstra for finding all-pairs shortest paths in sparse graphs, including graphs with negative edge weights. O(V²log V + VE) complexity.
Johnson's algorithm works in the following steps:
| Phase | Time |
|---|---|
| Bellman-Ford | O(VE) |
| V × Dijkstra | O(V(V log V + E)) |
| Total | O(V² log V + VE) |
For sparse graphs (E = O(V)), this is O(V² log V), better than Floyd-Warshall's O(V³).
Definition in file Johnson.H.