Note: This algorithm is better known as Gabow's SSSP algorithm.
This is an explanation on finding the single-source shortest path using a modifed breadth-first-search algorithm called "step-expansion". Step-expansion can solve SSSP on cyclic graphs with arbitrary edge weight. It accomplishes this by simulating extra steps in the traversal process by "expanding" a large weighted edge into several segmented edges or "steps".
Initially, the step-expansion only worked on arbirtrarily weighted DAG. This stage of development can be found under the "DAG" branch.
The algorithm runs in O(V + E*W) where W is the maximum edge weight in the graph. More precisely, the algorithm runs in O(V + E + W) time where W is the summation of all edge weights minus the total number of edges times the minimum edge weight. I use E + W because each edge e will be processed at least once and w as many times where w is the the difference between e.weight and the minimum edge weight. Therefore complexity is the sum of the number of vertices, the number of edges, and the number of additional times all edges have to be processed.
This algorithm depends heavily on W. Therefore I make the following recommendations:
- For arbitrarily weighted graphs: if W > VE then the use of Bellman-Ford's algorithm is preferred.
- For positive weighted graphs: if W > (V+E)logV then Dijkstra's is preferred.
- For all graphs: if W < min(V,E) then step-expansion is preferred.
The algorithm should be effective on any directed graph with arbitrary weights. The algorithm is an improvement over naïve BFS SSSP. BFS SSSP will always produce correct output for any DAG if and only if edge weight is constant across all edges. BFS Step-Expansion SSSP corrects this. Therefore, BFSE is effective for any positive weighted DAG. Further modifications to BFSE allow for it to be effective on any directed graph with arbitrary weights with or without cycles.
Formal proof and more inclusive testing is required to substantiate this claim. So far, in my limited testing, I have not discovered a counter-example.
The algorithm introduces three new properties: factor, step, and ideal weight. In order to use step-expansion, a graph must track factor and ideal weight. Additionally, each edge must track step. The algorithm can be optimized a bit by storing these values instead of finding them each time BFSE is called.
- Factor: the minimum edge weight found in the graph
- Step: a represenation of incremental traversal of a single edge
- Ideal weight: the summation of all negative edges in the graph
The algorithm can detect negative weight cycles if the weight of a path exceeds the ideal weight of the graph. A path can only have weight smaller than the ideal weight of the graph if and only if there exists a negative cycle along the path. That is, the ideal weight is the smallest possible weight a path can have without using a negative weight cycle.
Modified BFS from wikipedia (modifications are commented):