Speeding up shortest path algorithms
Given an arbitrary, non-negatively weighted, directed graph $G=(V,E)$ we present an algorithm that computes all pairs shortest paths in time $\mathcal{O}(m^* n + m \lg n + nT_\psi(m^, n))$, where $m^$ is the number of different edges contained in shortest paths and $T_\psi(m^*, n)$ is a running time of an algorithm to solve a single-source shortest path problem (SSSP). This is a substantial improvement over a trivial $n$ times application of $\psi$ that runs in $\mathcal{O}(nT_\psi(m,n))$. In our algorithm we use $\psi$ as a black box and hence any improvement on $\psi$ results also in improvement of our algorithm. Furthermore, a combination of our method, Johnson’s reweighting technique and topological sorting results in an $\mathcal{O}(m^*n + m \lg n)$ all-pairs shortest path algorithm for arbitrarily-weighted directed acyclic graphs. In addition, we also point out a connection between the complexity of a certain sorting problem defined on shortest paths and SSSP.
💡 Research Summary
The paper tackles the classic all‑pairs shortest‑paths (APSP) problem on a directed graph with non‑negative edge weights, aiming to improve upon the naïve approach of invoking a single‑source shortest‑paths (SSSP) algorithm ψ n times. The authors introduce a new parameter m* — the number of distinct edges that actually appear in any shortest‑path tree across all source vertices. By focusing computational effort only on these edges, they derive an APSP algorithm whose running time is
O(m* · n + m log n + n · Tψ(m*, n)),
where Tψ(m*, n) denotes the time required by ψ when it processes a graph with m* edges and n vertices. This bound is a substantial improvement over the trivial O(n · Tψ(m, n)) bound, especially when m* ≪ m, as is typical in sparse or near‑tree graphs.
The algorithm works as follows. First, a global priority queue (or a one‑time sorting of the edge list) is built in O(m log n) time. Then, for each source vertex s, ψ is executed, but every time ψ attempts to relax an edge, the algorithm checks whether this edge has already been relaxed in a previous source’s run. If it has, the relaxation is skipped; otherwise the edge is marked as “used” and its relaxation proceeds. Consequently, across all n executions, the total number of relaxations is bounded by m*. The heap operations that would normally be performed n times are now amortized over the whole algorithm, yielding the m log n term rather than n · m log n. The final distance vectors are stored after each run, giving the full APSP matrix.
A particularly elegant specialization is presented for directed acyclic graphs (DAGs) with arbitrary edge weights, including negative ones. By applying Johnson’s re‑weighting technique (a single Bellman‑Ford run from a dummy source) the graph is transformed so that all edge weights become non‑negative. On this re‑weighted DAG, a topological order can be computed, and a linear‑time dynamic‑programming SSSP algorithm can be run from each source. Combining this with the m*‑based edge‑sharing yields an overall APSP running time of
O(m* · n + m log n),
which eliminates the dependence on Tψ entirely for DAGs.
Beyond algorithmic design, the authors explore a theoretical connection between APSP and a “Shortest‑Path‑Sorting” problem: given all pairwise distances, sort them in non‑decreasing order. They prove that if this sorting can be performed in O(m* · n) time, then any SSSP algorithm ψ must have a comparable lower bound, establishing a complexity equivalence between the two tasks. This insight suggests that improvements in SSSP directly translate into faster sorting of shortest‑path distances, and vice‑versa.
The paper’s contributions can be summarized as:
- Introducing m* as a fine‑grained measure of the intrinsic work needed for APSP, leading to a tighter runtime bound.
- Providing a black‑box reduction from APSP to any SSSP algorithm, preserving improvements in ψ automatically.
- Achieving an O(m* · n + m log n) APSP algorithm for arbitrarily weighted DAGs by integrating Johnson’s re‑weighting and topological sorting.
- Demonstrating a complexity relationship between shortest‑path sorting and SSSP, opening a new avenue for theoretical exploration.
Overall, the work offers both practical speedups for graphs where m* is small and a deeper theoretical understanding of the interplay between single‑source and all‑pairs shortest‑path computations.