All-Pairs Shortest Paths (APSP)
- All-Pairs Shortest Paths (APSP) is the problem of computing the shortest path distances for all ordered or unordered pairs of vertices in a graph, essential in combinatorial optimization and distributed computing scenarios
- APSP algorithms range from classic methods like Floyd-Warshall with O(n^3) complexity to more advanced approaches for specific graph structures and distributed models
- Research in APSP includes dynamic, decremental, and output-sensitive algorithms, as well as hardware acceleration methods to improve performance for large-scale graphs.
All-pairs shortest paths (APSP) is the problem of computing the shortest-path distance for every ordered pair of vertices in a weighted directed or undirected graph , where
A missing edge is assigned weight . Depending on the formulation, APSP may also require shortest-path witnesses, shortest-path DAGs, path multiplicities, or queries and updates to a maintained distance structure. APSP is a central problem in combinatorial optimization, graph algorithms, distributed computing, dynamic algorithms, fine-grained complexity, and hardware acceleration. Its unrestricted sequential baseline is through Floyd–Warshall or straightforward repeated single-source shortest paths, while the best general classical bound cited in the literature is , which is not truly subcubic in the usual sense (Nayebi et al., 2014).
1. Problem definition, computational structure, and classical baselines
For a graph with , APSP outputs an distance matrix. In directed graphs, ordered pairs must be distinguished; in undirected graphs, distances are symmetric, although algorithms may still represent both orientations. The standard model permits arbitrary real weights when negative cycles are excluded. Positive or nonnegative weights are frequently assumed for algorithms based on Dijkstra’s method, while DAG algorithms can accommodate arbitrary real weights because acyclicity precludes negative cycles.
The central algebraic operation is the distance product, or min-plus product,
Repeated min-plus squaring computes the closure of a weighted adjacency matrix. If there are no negative cycles, a shortest simple path uses at most 0 edges, so repeated squaring requires 1 distance products. Floyd–Warshall instead applies the recurrence
2
which yields 3 time and 4 space.
For sparse graphs with nonnegative weights, Johnson’s algorithm has running time
5
although dense matrix-based algorithms may have higher computational density in practice. In undirected unweighted graphs, Seidel’s algorithm computes exact APSP in 6 time, where 7 is the exponent of square matrix multiplication. The distinction between weighted and unweighted graphs is fundamental: exact unweighted undirected APSP admits algebraic subcubic algorithms, whereas exact weighted APSP remains associated with the weighted APSP conjecture, which asserts that no truly subcubic algorithm exists for general weighted instances.
The output size alone imposes an 8 lower bound when all distances are explicitly produced. This lower bound is approached by several approximate algorithms, but exact general weighted APSP remains substantially more expensive.
2. Algorithmic paradigms for static APSP
A recurring technique is to separate shortest paths by hop length. For a parameter 9, paths are divided into short paths containing at most 0 vertices or edges and long paths containing at least 1 vertices. Short paths are computed using matrix products or specialized recurrences. Long paths are handled by a hitting set, or blocker set, of size approximately 2 that intersects every relevant long shortest path.
If 3 is such a set, then for pairs whose shortest paths are long,
4
Quantum algorithms use this framework with Grover search and quantum Dijkstra. A quantum Dijkstra computation costs 5 per source, while a direct Grover evaluation of one distance-product entry costs 6. Consequently, the unrestricted quantum baseline for APSP is
7
obtained by evaluating all 8 entries of a distance product. Structured instances permit improvements below this baseline, but the cited quantum work does not provide a truly sub-9 algorithm for unrestricted APSP (Nayebi et al., 2014).
Geometric structure provides one such improvement. In geometrically weighted graphs, edge weights are generated by a constant-size family of piecewise-algebraic functions over points in constant-dimensional space. A geometric partition theorem bounds the number of cells intersected by a relevant algebraic boundary. If 0 is the corresponding partition parameter, a geometric distance product can be computed in
1
time. For node-weighted graphs, 2, giving approximately 3 for the product; for Euclidean graphs, 4, giving approximately 5.
Applying the product repeatedly to short paths and a hitting-set method to long paths yields geometric APSP in
6
The stated special cases are approximately 7 for node-weighted graphs and 8 for Euclidean graphs. For geometrically weighted graphs with edge weights in 9, sparsity of intermediate matrices gives the stronger bound
0
Other structured variants exploit a bounded number of outgoing weight values per vertex, or monotonicity constraints. For at most 1 distinct outgoing weights per vertex, the cited quantum bound is
2
For all-pairs nondecreasing paths, also called earliest-arrival paths, specialized 3 products and a modified quantum Dijkstra procedure yield
4
These improvements are conditional on structural restrictions; they do not establish a general 5 quantum algorithm.
3. Distributed and parallel APSP
Distributed APSP depends strongly on the communication model. In the Congest model, nodes communicate synchronously over graph edges using 6-bit messages, and complexity is measured in rounds. A deterministic exact weighted algorithm based on bounded-hop shortest-path trees and blocker sets computes APSP in
7
rounds. The construction chooses
8
builds all 9-hop shortest-path trees, constructs a blocker set of size 0, runs full single-source shortest paths from blocker vertices, and reconstructs every distance using
1
A subsequent deterministic algorithm improves the Congest bound to 2 for arbitrary nonnegative real weights in directed and undirected graphs (Agarwal et al., 2020). It uses 3, a deterministic blocker construction based on approximate hypergraph set cover, and a deterministic frame-based round-robin schedule for propagating source-to-blocker distances. The blocker set has size 4, and both the 5-hop computations and the central propagation step take 6 rounds.
For directed unweighted graphs, pipelined source-distance records yield linear-round algorithms. A node orders source-distance pairs by distance and source identifier, and schedules transmissions using distance plus list position. The resulting algorithm computes exact APSP in
7
rounds for strongly connected graphs, where 8 is the directed diameter, with at most 9 messages. The same shortest-path DAG and path-count information supports betweenness centrality. For weighted DAGs, longest-length-tree scheduling separates concurrent source computations, yielding exact APSP in 0 rounds, where 1 is the maximum directed path length in edges (Pontecorvi et al., 2018).
A different deterministic distributed algorithm handles nonnegative integer weights, including zero weights, using a combined distance–hop scheduling key. For a path of weighted length 2 and hop length 3, the key is
4
where 5 is the hop bound, 6 is the number of sources, and 7 is a distance bound. The additive hop term ensures strict progress even over zero-weight edges. The resulting 8-source shortest-path computation takes
9
rounds; APSP up to distance 0 takes
1
rounds.
In the Congest- Clique model, every pair of nodes communicates directly. Classical exact APSP uses 2 rounds, while quantum communication gives an algorithm using
3
rounds for directed graphs with integer weights in 4, with high probability (Izumi et al., 2019). The algorithm reduces distance products to negative-triangle detection and uses parallel quantum searches whose congestion is controlled by random partitions and replication. In the classical Congested Clique, randomized approximate APSP for weighted undirected graphs can be performed in 5 rounds with an 6 approximation. More generally, 7 rounds yield an
8
approximation (Bui et al., 2024).
Static parallel APSP also admits a work-depth tradeoff for real-weighted directed graphs. For every 9, a deterministic algorithm achieves
0
work and 1 depth (Karczmarz et al., 2021). The method constructs deterministic hub sets for shortest 2-hop paths, performs bounded-hop Bellman–Ford computations, solves a dense APSP instance on the hub vertices, and lifts distances through the hub hierarchy. For sparse graphs, choosing 3 around 4 makes the work nearly 5.
4. Dynamic, decremental, and output-sensitive APSP
Dynamic APSP maintains distances while the graph changes. In decremental settings, updates delete vertices or increase incident edge weights. A stronger problem, all-pairs all-shortest-paths (APASP), maintains every shortest-path DAG and the multiplicity of shortest paths, not merely one distance per ordered pair.
For positive-weight directed graphs, APASP can be represented compactly with tuples and triples. A tuple
6
represents paths sharing the first edge 7 and last edge 8, while a triple 9 stores the common weight and number of represented paths. The data structure maintains locally shortest paths, shortest-path tuples, extension sets, priority queues, and path multiplicities. The key parameter is
0
The decremental algorithm performs cleanup of paths containing the updated vertex and fixup of newly relevant paths. Its amortized update time is
1
with space 2, where 3 is the number of edges lying on at least one shortest path. If every vertex lies on 4 shortest-path edges, including the case of constantly many shortest paths per ordered pair, the bound becomes 5 per update. The same path-count information supports decremental betweenness centrality (Nasre et al., 2014).
Fully dynamic exact APSP supports both vertex insertions and deletions. Earlier structures achieved 6 amortized update time but used 7 space, while Thorup’s worst-case structure used 8 update time and supercubic space. Space-efficient deterministic structures reduce the worst-case weighted update time to
9
and the unweighted bound to
00
A simpler deterministic structure achieves 01 for weighted graphs and 02 for unweighted graphs using 03 space. A Las Vegas structure achieves 04 for weighted graphs and 05 for unweighted graphs, also with near-quadratic space and tolerance of a non-oblivious adversary (Gutenberg et al., 2020).
Dynamic APSP in planar graphs has stronger specialized bounds. For planar directed graphs with positive edge weights and an offline sequence of edge-weight changes, dynamic dense distance graphs can be maintained in 06 worst-case update time for an 07-capped recursive decomposition. FR-Dijkstra answers arbitrary distance queries in 08 time. Setting 09 gives
10
The balanced choice 11 gives 12 for both operations, matching conditional lower bounds up to polylogarithmic factors in the offline setting. The same bound holds online for incremental weight decreases, but not for fully online arbitrary increases and decreases (Das et al., 1 Jun 2026).
Approximate dynamic APSP admits substantially smaller update and query overheads. For undirected nonnegative weighted graphs undergoing fully dynamic edge updates, a deterministic neighborhood-cover and emulator framework achieves a large multiplicative approximation of the form
13
with amortized update time 14 and distance-query time
15
where 16 is the ratio of maximum to minimum edge length. Shortest-path queries additionally require time proportional to the returned path length (Chuzhoy et al., 2023).
Warm-start methods reuse a previously computed distance matrix after a small modification. Adding a vertex can be handled by computing distances to and from the new vertex using the old matrix, then updating old-old pairs by
17
This requires 18 work. Vertex deletion identifies potentially affected ordered pairs using the condition
19
then selectively reruns Dijkstra; the best case is 20 and the worst case is 21 (Liu, 2024).
5. Approximation, DAG structure, and fine-grained complexity
Approximate APSP is often expressed through multiplicative, additive, or bicriteria guarantees. A multiplicative 22-approximation returns
23
while an additive 24 approximation satisfies
25
Since 26 whenever 27, additive approximations can yield multiplicative 28-approximations for sufficiently distant pairs.
For unweighted undirected graphs, recent algorithms combine degree decompositions, dominating sets, low-degree residual graphs, and rectangular matrix multiplication. A randomized 29-approximation achieves expected time
30
and a deterministic version achieves
31
The same framework improves additive approximations, including approximately 32 for 33 and 34 for 35 (Saha et al., 2023). A later cluster-decomposition approach obtains randomized bounds of 36 for 37, 38 for 39, and 40 for 41, using constant-diameter clusters and standard fast matrix multiplication rather than bounded-difference min-plus products (Jin et al., 6 Nov 2025).
A near-quadratic randomized algorithm gives a factor-42 approximation for every pair whose distance is at least a fixed constant 43, with high probability, in 44 time. The construction uses sampled pivots, balls, clusters, low-degree path segments, and rectangular matrix multiplication for dense local neighborhoods. The explicit constant in the analysis is at most 45 (Gupta et al., 21 Jul 2026). This result approaches the 46 output-size bound, but does not establish a factor-47 guarantee for all pairs without a distance threshold.
DAGs provide another form of structure. Standard SSSP in a DAG takes 48 time after topological sorting, and running it from every source takes 49. An output-sensitive algorithm instead stores lexicographically first shortest paths in trees 50 rooted at each destination. Its running time is
51
The second term measures the number of independent shortest-path branches. When the trees have few leaves, extensive path sharing reduces the cost; when they are highly branched, the bound approaches the standard 52 scale (Lingas et al., 2021).
Fine-grained complexity treats exact weighted APSP as a source of conditional lower bounds. The APSP conjecture asserts that general weighted APSP cannot be solved in truly subcubic time. Approximation below factor 53 in unweighted undirected graphs is closely connected to Boolean matrix multiplication. These barriers do not preclude instance-sensitive algorithms. A learning-augmented algorithm can accept, for each pair 54, a predicted set of intermediate vertices likely to lie on shortest routes. If 55 counts incorrect or unverifiable pair entries, the cited running time is
56
The algorithm remains correct for arbitrary predictions and degrades to the cubic scale when 57 (Polak et al., 1 Jul 2026).
6. Implementations, hardware acceleration, and practical limitations
APSP implementations must address both arithmetic work and data movement. Distributed-memory Spark implementations use blocked min-plus products, blocked Floyd–Warshall, or repeated squaring. The strongest Spark design for large undirected weighted graphs uses blocked collect/broadcast operations and shared persistent storage. It handled instances with more than 58 vertices on a 1,024-core cluster, but remained slower than an optimized MPI divide-and-conquer implementation and was not fully fault-tolerant because external files lay outside the RDD lineage (Schoeneman et al., 2019).
The principal engineering parameters are block size, data partitioning, synchronization frequency, and storage traffic. Scalar Floyd–Warshall exposes 59 global iterations, while blocked methods reduce this to approximately 60 iterations for block size 61. Larger blocks reduce synchronization but increase local computation and reduce parallelism. Sparse graph structure is difficult to exploit in dense matrix formulations because absent edges are represented by 62 and all matrix blocks participate in the computation.
Processing-in-memory architectures target the data-movement bottleneck of dense Floyd–Warshall. PIM-FW places specialized bit-serial processing elements inside HBM3 banks and channel-level processing elements near memory controllers. The blocked computation retains the three dependency phases: pivot-tile update, pivot-row and pivot-column update, and off-diagonal tile update. An interleaved tile mapping distributes blocks across channels and bank groups. The architecture performs the dominant min-plus operations in memory while reserving near-memory processing for cross-bank reductions.
In cycle-accurate simulation, PIM-FW reportedly achieves an 63-fold end-to-end speedup and more than a 64-fold DRAM-energy reduction over an optimized GPU-only Floyd–Warshall implementation for an 65 distance matrix (Lu et al., 20 Dec 2025). These results are simulation-based and apply to the dense Floyd–Warshall representation; specialized sparse algorithms may remain preferable for genuinely sparse inputs.
Across algorithmic settings, several limitations recur. Exact APSP generally requires 66 output space, and many algorithms require additional matrices or shortest-path representations. Negative cycles make ordinary shortest-path distances undefined. Distributed bounds depend on bandwidth, topology, message size, and whether communication may use underlying undirected links. Dynamic bounds distinguish amortized from worst-case time, online from offline updates, and deterministic from randomized guarantees. Approximation results may depend on graph direction, nonnegative or unweighted edges, distance thresholds, or large hidden constants.
The main unresolved objectives include a general truly subcubic exact algorithm for weighted APSP, a deterministic near-quadratic algorithm for factor-67 approximation on all unweighted undirected pairs, sub-68 fully online dynamic APSP in planar digraphs, and practical implementations whose communication and memory costs match their asymptotic arithmetic bounds.