TOPICS
Search

All-Pairs Shortest Path


The all-pairs shortest path problem is the determination of the shortest graph distances between every pair of vertices in a given graph on n vertices. For nonnegative edge weights, the problem can be solved using n applications of Dijkstra's algorithm. The Floyd-Warshall algorithm also works for a weighted graph with negative edge weights, provided there is no negative-weight cycle.

The matrix of all distances between pairs of vertices is called the graph distance matrix, or sometimes the all-pairs shortest path matrix.

The graph distance matrix of a graph g can be found in the Wolfram Language using GraphDistanceMatrix[g], and a shortest path between two vertices u and v using FindShortestPath[g, u, v].

Alman and Vassilevska Williams (2026) reported a deterministic algorithm running in O(n^(2.9995)) time on a word random access machine with O(lnn)-bit words for a directed graph on n vertices with polynomially bounded integer edge weights and no negative-weight cycles. This refutes the truly subcubic all-pairs shortest path hypothesis. Alman and Vassilevska Williams (2026) state that Claude discovered the core algorithm, which they checked and extended, and also report a Lean 4 formalization. The same method gives a truly subquadratic 3SUM problem algorithm.


See also

3SUM Problem, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Graph Distance, Graph Distance Matrix, Graph Geodesic, Shortest Path Problem

Explore with Wolfram|Alpha

References

Alman, J. and Vassilevska Williams, V. "Truly Subquadratic 3SUM and Truly Subcubic APSP via Triangles in Sparse Lopsided Graphs." 5 Oct 2026. https://arxiv.org/abs/2610.06783.Pemmaraju, S. and Skiena, S. "All-Pairs Shortest Paths." §8.1.2 in Computational Discrete Mathematics: Combinatorics and Graph Theory with Mathematica. Cambridge, England: Cambridge University Press, pp. 330-331, 2003.Skiena, S. "All Pairs Shortest Paths." §6.1.2 in Implementing Discrete Mathematics: Combinatorics and Graph Theory with Mathematica. Reading, MA: Addison-Wesley, pp. 228-229, 1990.

Referenced on Wolfram|Alpha

All-Pairs Shortest Path

Cite this as:

Weisstein, Eric W. "All-Pairs Shortest Path." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/All-PairsShortestPath.html

Subject classifications