Manuscript Offprint
arXiv:2611.05311Roundtrip All-Pairs Shortest Paths in Directed Graphs
Abstract
We study approximation algorithms for All-Pairs Shortest Paths (APSP) in directed graphs under the roundtrip metric. In undirected graphs, approximate APSP has been studied extensively, yielding a rich landscape of tradeoffs between approximation stretch and running time, from the classical exact algorithm toward the output-size barrier. In directed graphs, however, even finite-factor approximation of ordinary one-way distances must distinguish reachable from unreachable vertex pairs, and therefore computes transitive closure, a problem equivalent to Boolean matrix multiplication (BMM) under standard reductions. The roundtrip distance, defined as , offers a natural and robust relaxation. It measures the cost of traveling from to and back, satisfies the triangle inequality, and is inherently symmetric. While this metric has become central to the study of directed roundtrip spanners and compact routing, the fundamental problem of all-pairs roundtrip distance approximation has remained largely unexplored. In this work, we present a comprehensive study of roundtrip APSP and distance oracles, presenting several new lower and upper bounds. On the algorithmic side, our main result is a combinatorial algorithm that computes a stretch-3 approximation to all-pairs roundtrip distances in time. For edge weights in , we also obtain a -approximation in time and a -approximation in time using fast matrix multiplication. On the hardness side, we show that any stretch below 3 would imply a breakthrough for BMM. We also obtain additional tradeoffs between stretch and running time.
1 Introduction
The All-Pairs Shortest Paths (APSP) problem is one of the most fundamental problems in graph algorithms. Given a graph with nonnegative edge weights, the goal is to compute the shortest-path distance between every ordered pair of vertices. For dense graphs with real nonnegative edge weights, the classical algorithm of Floyd–Warshall [1] runs in time, and the fastest known exact algorithms improve over this bound only by factors (see [2]). A central hypothesis in fine-grained complexity asserts that no -time algorithm can solve APSP in edge-weighted graphs, for any fixed (see [3]). Consequently, most progress toward faster algorithms has relied on either approximation techniques, or algebraic methods such as fast matrix multiplication combined with restrictions on the edge weights.
*Tel Aviv University, Israel. E-mail: shiri.chechik@gmail.com, gurlifshitz@gmail.com.
Approximating Undirected APSP The study of approximate APSP in undirected graphs dates back to the late 1990s. In unweighted graphs, Aingworth et al. [4] gave a combinatorial +2-approximation in time, and Dor, Halperin, and Zwick [5] improved the running time to . Roditty [6] gave a combinatorial stretch-2 algorithm in time, and Dory et al. [7] and independently Saha and Ye [8] obtained an algebraic stretch-2 algorithm in time. For weighted graphs, Cohen and Zwick [9] established the classical tradeoffs, including stretch 3 in near-quadratic time, stretch 7/3 in time, and stretch 2 in time. Baswana and Kavitha [10] obtained a combinatorial stretch-2 algorithm running in time. Further combinatorial and algebraic tradeoffs for weighted and unweighted graphs can be found in, e.g., [11, 12, 13, 14].
Approximating Directed APSP The directed case is substantially less understood. For exact APSP with small integer weights, Alon, Galil, and Margalit [15] gave an -time algorithm, and Zwick [16] later improved this to using rectangular matrix multiplication; this remains the fastest known exact bound even for unweighted directed graphs. Zwick also showed that, for polynomially bounded weights, a -approximation can be computed in time. Roditty and Shapira [17] later obtained algebraic additive-error tradeoffs, achieving additive error in time for every .
Any multiplicative approximation to directed distances must distinguish finite from infinite distances, and therefore computes transitive closure. Since transitive closure and Boolean matrix multiplication are equivalent under standard reductions [18, 19], such an approximation algorithm would also yield an algorithm for Boolean matrix multiplication with essentially the same running time. This motivates studying the roundtrip metric.
Roundtrip Distances A central concept in the analysis of directed graphs is the roundtrip distance, introduced by Cowen and Wagner [20]. This metric is motivated by the observation that two vertices are often meaningfully close only if one can travel from one to the other and back at small total cost. For vertices , the roundtrip distance is defined as
that is, the total length of the shortest directed closed walk passing through both and . This measure is symmetric and satisfies the triangle inequality, inducing a metric on every strongly connected component of .
One way to view this metric is through the complete undirected graph on the vertex set , where the edge has weight . The difficulty is that is dense and implicit: computing its edge weights exactly is essentially the directed APSP problem. Thus, the challenge is to exploit the undirected metric structure of roundtrip distances without explicitly constructing the metric.
The roundtrip metric has played a central role in directed spanners and routing. Roditty, Thorup, and Zwick [21] initiated the study of roundtrip spanners for directed graphs, showing general -roundtrip spanners with edges, extending these constructions to compact roundtrip routing schemes, and proving that every weighted directed graph admits an optimal-size
The notation hides polylogarithmic factors in .
3-roundtrip spanner with edges. Later work developed faster constructions of roundtrip spanners and closely related algorithms for directed-girth approximation.
Chechik, Liu, Rotem, and Sidford [22] were the first to obtain a constant-factor approximation for the directed girth in subquadratic time, achieving a 3-approximation in time. Using closely related techniques, they also showed how to construct an 8-roundtrip spanner with edges in the same running time.
Dalirrooyfard and Vassilevska Williams [23] subsequently obtained a -approximation for weighted directed girth in time, together with a -roundtrip spanner with edges in the same running time.
Building on this line of work, Chechik and Lifshitz [24] gave a 2-approximation for the girth in time. They also presented a different algorithm that computes both a 2-approximation for the girth and a 4-roundtrip spanner with edges in time. More recently, Harbuzova, Jin, Vassilevska Williams, and Xu [25] further extended these ideas to obtain a 3-roundtrip spanner with edges in time. The roundtrip metric has also found applications in compact routing and more roundtrip spanner constructions; see, e.g., [21, 26, 27].
Lower Bounds. For directed girth, Dalirrooyfard and Vassilevska Williams [23] showed that, under the -Cycle Hypothesis, no -time algorithm can achieve a -approximation, for any constants .
First ingredient: pivots and truncated searches. Our first ingredient is a stretch-3 roundtrip distance oracle. Querying the oracle in both directions then yields a stretch-3 approximation to the roundtrip distance.
Theorem 1.1. There exists a 3-roundtrip distance oracle of expected size , constructible in expected time and with query time . Specifically, for every pair of vertices , the oracle returns a value satisfying
In particular, combining the estimates for and yields a 3-approximation to the roundtrip distance .
This result can be viewed as a fast-construction analogue of the stretch-3 roundtrip spanner of Roditty, Thorup, and Zwick [21]. By querying this oracle on all vertex pairs, we obtain the following all-pairs approximation.
Corollary 1.2. For any directed graph with nonnegative edge weights, one can compute a 3-roundtrip APSP approximation in expected time .
Second ingredient: sparsification. Our second ingredient is a fast sparsification procedure that preserves roundtrip distances approximately. After the sparsification procedure we run the distance oracle on a sparser graph and obtain a faster approximation for dense graphs.
Theorem 1.3. There exists a randomized combinatorial algorithm that computes a 4-roundtrip APSP approximation in expected time .
The main combinatorial upper bound is obtained by combining the two ingredients. Instead of running the sparsification step and then exploring the sparsified graph with the pivot machinery, we do both in parallel. This improves the stretch back to 3 and beats the bound on dense graphs.
Theorem 1.4. There exists a randomized combinatorial algorithm that, in expected time , computes estimates for all ordered pairs satisfying
In particular, this yields a 3-approximation to all-pairs roundtrip distances.
For dense graphs, Theorem 1.4 gives a 3-APSP algorithm running in time.
Lower bounds: reductions from Boolean matrix multiplication. We complement our algorithms with two reductions from Boolean Matrix Multiplication. The first shows that improving the roundtrip stretch below 3 would yield a corresponding improvement for BMM.
Theorem 1.5. For every constant , a -approximation algorithm for roundtrip APSP on -vertex directed unweighted graphs running in time implies a Boolean matrix multiplication algorithm running in time .
The second reduction explains the asymmetric guarantee obtained by our algorithms. It shows that the coefficient 2 of the forward distance cannot be improved, even if the reverse distance is allowed an arbitrary constant coefficient.
Theorem 1.6. For all constants and , an algorithm that, on -vertex directed unweighted graphs, computes estimates satisfying
for all ordered pairs in time implies a Boolean matrix multiplication algorithm running in time .
Thus, our lower bounds match the two main features of our stretch-3 algorithms: the final roundtrip stretch and the asymmetric one-way guarantee used to obtain it.
Further upper bounds. The same techniques yield additional tradeoffs. First, by using a faster distance query and allowing a larger asymmetric error, we obtain a near-quadratic distance oracle.
Theorem 1.7. There exists a distance oracle of expected size that can be constructed in expected time and answers each query in time. For every pair of vertices , the oracle returns a value satisfying
Table 1: Summary of our upper and lower bounds for approximating all-pairs roundtrip distances in directed graphs. The algebraic bounds assume edge weights in [1, W].
| Approximation | Type | Running Time / Barrier | Reference |
|---|---|---|---|
| 3 | Combinatorial | Corollary 1.2 | |
| 3 | Combinatorial | Theorem 1.4 | |
| 4 | Combinatorial | Theorem 1.3 | |
| 5 | Combinatorial | Corollary 1.8 | |
| Algebraic | Theorem 1.10 | ||
| Algebraic | Theorem 1.9 | ||
| Lower bound | BMM reduction | Theorem 1.5 | |
| Lower bound | BMM reduction | Theorem 1.6 |
Querying all pairs gives a 5-approximation in time almost matching the output size.
Corollary 1.8. For any directed graph with nonnegative edge weights, one can compute a 5-roundtrip APSP approximation in expected time .
Finally, when edge weights are bounded, some of the all-pairs aggregation steps in our algorithms can be accelerated using rectangular approximate min-plus products. This gives algebraic improvements over the combinatorial running times.
Theorem 1.9. Assume all edge weights lie in [1, W]. There exists a randomized algorithm that computes a -roundtrip APSP approximation in expected time .
Theorem 1.10. Assume all edge weights lie in [1, W]. There exists a randomized algorithm that computes a -roundtrip APSP approximation in expected time .
Organization. Section 2 introduces notation and key tools. In Section 3, we present the first tool and use it to obtain a 3-roundtrip distance oracle and APSP algorithm. In Section 4, we present the second tool and use it to obtain a 4-approximation algorithm. In Section 5, we combine these tools to obtain a faster 3-approximation APSP algorithm. Section 6 presents the lower bounds. Appendix A completes the analysis of Section 3. Appendix B gives the near-quadratic 5-approximation algorithm, and Appendix C presents the algebraic accelerations.
2 Preliminaries
Let be a directed input graph with nonnegative edge weights . For a directed graph , let and denote the vertex and edge sets of , respectively. For every , denote by the (shortest path) distance from to in . If there is no path from to , we set . Moreover, let be the shortest closed walk containing and , and the roundtrip distance between and as (which is the length of that shortest closed walk). When the underlying graph is clear, we drop the subscript and write instead of . Let be the outgoing neighbors of .
Roundtrip distance oracles. A (roundtrip) approximate distance oracle for a directed graph is a data structure that, after preprocessing , can answer queries for any pair of vertices with an estimate of the roundtrip distance . An oracle has stretch if for all ,
The performance of an oracle is measured by its preprocessing time, space usage, and query time.
Stored-distance interface. Our distance oracles maintain a sparse set of stored directed distances. Formally, we view the stored data as a partial function
where (the domain of ) iff the construction explicitly stored a value for this pair. For notational convenience, we extend to all pairs by defining
We assume standard expected dictionary access.
Degree balancing. We assume throughout that for every . This is without loss of generality: the standard degree-reduction transformation of [22] produces, in time, a graph with vertices and edges, maximum outdegree , and the same distances between the original vertices.
3 The Pivot Machinery and the First 3-APSP Approximation
This section is devoted to the proof of Theorem 1.1 and its application to APSP, Corollary 1.2. We first isolate the main pivot mechanism, which is based on an observation of Chechik and Lifshitz [24], and then show how to turn it into a distance oracle.
This should be viewed as a baseline result. The pivot mechanism is based on known ideas, but we use it here to obtain the distance-oracle needed for roundtrip APSP. This also introduces the main primitive that will later be combined to obtain a faster algorithm. Since the analysis closely follows the known arguments, its full details are deferred to Appendix A.
3.1 The Pivot Machinery
The starting point is the following question. Suppose that all distances to and from a vertex have already been computed. For which pairs can be used to estimate , and what does this imply for the corresponding roundtrip distances?
Chechik and Lifshitz [24] observed that it suffices to test the following comparison. If, for vertices ,
then provides the guarantees stated in the following lemma.
Lemma 3.1 (Chechik–Lifshitz [24]). Let be a directed graph with nonnegative edge weights, and let . If (1) holds, then
Moreover,
Figure 1 illustrates the lemma. Intuitively, if r passes the comparison (1), then the cycle through v, u can be replaced, up to a factor 2, by a cycle that goes through the pivot r.

Figure 1: An illustration of Lemma 3.1. The directed cycle (red) can be 2-approximated by the directed cycle (green) when (1) holds.
The important algorithmic point is not only that a pivot can provide a good approximation for one pair, but also that a random pivot can provide good approximations for many pairs simultaneously. Fix a vertex , and consider some active set of vertices whose distance from do not have a good enough approximation. For every two vertices , at least one of the two comparisons
or
holds. Thus, for the fixed source , these comparisons orient every pair in . If the first inequality holds, we say that eliminates with respect to .
This creates a tournament on the active set . Consequently, a uniformly random pivot eliminates half of the remaining vertices in expectation. The oracle below implements this idea implicitly: it samples pivots at increasing rates, stores distances to and from them, and then runs a truncated search from every vertex , continuing only through vertices that have not been eliminated by an already chosen pivot.
We now show how to turn this pivot-elimination mechanism into a 3-roundtrip distance oracle. Querying the oracle on all pairs then gives Corollary 1.2 in total expected time .
3.2 Construction Overview
The oracle preprocessing proceeds in two phases.
Phase 1: Sample the pivots. Set
Note that for and . For each vertex , the oracle maintains a pivot set , initially empty.
For iterations , the algorithm samples a set by including each vertex independently with probability , so that . For each sampled witness , it runs both outgoing and incoming Dijkstra searches rooted at in the original graph . The oracle stores these distances by setting and for all and .
After processing the witnesses in , it updates pivots: for each , if there exists a witness such that for every ,
then it adds one such to (choosing one uniformly at random if multiple exist). Note that all those distances are stored via . This ensures that by the end of Phase 1 we have for every .
Phase 2: truncated outgoing searches. After iterations, for each vertex , the algorithm runs an outgoing Dijkstra search rooted at , but truncates the search using the current pivot set .
Concretely, when a vertex is extracted from the priority queue, let denote its current distance label. The algorithm scans the outgoing edges of only if, for every pivot ,
Let denote the resulting truncated search tree rooted at .
For each vertex , the oracle stores the distance found by the search by setting , where denotes the length of the path from to in .
In the analysis, we show that for every , implying that the oracle stores only total space in expectation. The construction is given in Algorithm 1.
Algorithm 1: Construction of a 3-roundtrip distance oracle
1 Input: Directed graph with
2 Output: Distance oracle
3 Set , .
4 Set for each .
5 Phase 1: Sample the pivots
6 for to do
7 Sample by including each vertex independently with probability .
8 Run outgoing and incoming Dijkstra from each in
9 Set , for every and
10 foreach do
11 if such that
then
12 Add one such to .
13 Phase 2: Truncated searches
14 foreach do
15 Run outgoing Dijkstra from . When a vertex with current distance label is extracted, scan its outgoing edges only if
Let the resulting truncated tree be .
16 Set for all
17 Add to
Distance query. Given , the oracle returns the minimum of distances from to via a pivot using the stored information function :
Since , the query time is . We summarize the query in Algorithm 2.
Algorithm 2: Query procedure for
1 Input: Vertices
2 Output: Approximate distance
3 return .
The analysis of the algorithm with its full proofs appears in Appendix A.
4 Sparsification Using Centers and the 4-APSP Approximation
In this section, we prove Theorem 1.3. The main ingredient is a sparsification idea of Chechik and Lifshitz [24], originally used for constructing 4-roundtrip spanners. We adapt it to the all-pairs setting by storing distance estimates before deleting edges.
4.1 Sparsification Using Centers
We now turn to the second ingredient of our framework. As in the pivot machinery, suppose that we have already computed shortest paths from and to a vertex . Consider an edge such that eliminates with respect to , namely, such that (1) holds.
This means that is a good replacement for the local edge , but the consequence is stronger. If a shortest path from to uses the edge , then the path produces a good approximation for the distance . In particular, if lies on the shortest roundtrip , then the cycle
has length at most .
Our sparsification procedure uses this observation as follows. We sample centers and use them to eliminate outgoing edges. Before deleting such an edge, we store roundtrip estimates through the center responsible for its deletion. In the setting above, when is responsible for the deletion of an edge on a shortest path from to , we obtain
(3)

Figure 2: An illustration of Inequality (3). The cycle (red) can be 2-approximated by the cycle (green) when (1) holds.
We use the sparsification procedure to construct a sparse subgraph , together with explicit estimates for all pairs whose shortest roundtrip is destroyed by the sparsification. The key guarantee is the following.
Lemma 4.1. Let be a directed graph with nonnegative edge weights, and let . There is a randomized algorithm that, in expected time , computes:
-
a subgraph of expected size , and
-
an estimate for every pair , such that the following holds for every pair :
-
, and
-
if the shortest roundtrip is not fully contained in , then
Our 4-approximation algorithm now follows directly. Apply Lemma 4.1 with parameter , obtaining a subgraph with expected edges and estimates . Then run the 3-approximation algorithm of Corollary 1.2 on . For every pair , if the shortest roundtrip is destroyed by the sparsification, the estimate is a 4-approximation. Otherwise, the shortest roundtrip remains in , and the 3-approximation on gives a valid, hence also 4-approximate, estimate in . Taking the minimum of the two estimates therefore gives a 4-roundtrip APSP approximation.
The running time is
Choosing balances the two terms and gives , proving Theorem 1.3.
4.2 Construction Overview
We now describe the algorithm achieving Lemma 4.1. The construction closely follows the 4-roundtrip spanner algorithm of Chechik and Lifshitz [24], with three major differences: (i) the sparsification process is stopped early, once the remaining graph has at most edges; (ii) in every iteration, roundtrip distances are explicitly aggregated via the sampled centers in order to obtain distance estimates for all vertex pairs; and (iii) the sampling technique of Harbuzova et al. [25] is incorporated.
The algorithm maintains a sequence of graphs , obtained by iteratively deleting edges, together with a table of roundtrip distance estimates. Initially, let . The algorithm sets
Note that for , and . For iterations , the following steps are executed.
Sampling centers. In iteration , a set is sampled by including each vertex independently with probability . Hence .
Computing distances and aggregating estimates. Let denote the current graph at the beginning of iteration . For every , outgoing and incoming Dijkstra searches are run in , yielding roundtrip distances .
For every pair of vertices , the algorithm updates the global estimates as
Edge pruning. For each vertex , let denote its outgoing neighbors in . If , a center is chosen uniformly at random.
The algorithm then inspects every edge . If has an assigned center and
the edge is deleted. Let denote the resulting graph.
Note that this is a slight modification of the original deletion rule: we replace by the current edge weight . This is needed because computing for every edge would be too expensive. The change is harmless, since always . If , then the edge cannot belong to any shortest roundtrip cycle in and can be removed.
After all iterations are completed, the algorithm returns . The pseudo-code is given in Algorithm 3.
Algorithm 3: Roundtrip Sparsification with 4-Approximation estimates
Input: Directed graph with , parameter .
Output: Subgraph and estimates .
1 Set ; and ; and ;
2 for to do
3
4
5
6
7
10
4.3 Analysis
We start by analyzing the stretch.
Lemma 4.2. Let . If the shortest roundtrip is not fully contained in , then
Proof. Let be a shortest roundtrip between and in , and let be the last iteration such that . Then there exists an edge on such that . See Figure 2.
The edge was deleted in iteration due to a center satisfying
Since lies on the shortest roundtrip , we have . Substituting this into the deletion inequality and using the triangle inequality yields
(6) where the last inequality holds since lies on the roundtrip .
Now fix any vertex on the roundtrip . Then
by (6)
where the last inequality follows from the fact that is exactly . Applying this bound with and implies
Therefore, in iteration i the algorithm sets
as claimed.
We next analyze the size of the remaining graph. Bounding the number of edges after each iteration follows essentially the same argument as in Claim A.2.1 (and Lemma 4.3 in [25]), so we do not repeat the full proof. The only difference is that Claim A.2.1 bounds, for each vertex , the size of the set , whereas here we bound the number of outgoing neighbors of v in iteration i.
Lemma 4.3. For every iteration i and every ,
In particular, since , it follows that
Lastly, we bound the expected running time of the sparsification procedure.
Claim 4.3.1. The sparsification procedure runs in expected time .
Proof. The running time has two components: distance aggregation and edge pruning.
Aggregation. In iteration , the algorithm enumerates all centers and all ordered pairs to update , which takes time. Since and , the total expected time spent on aggregation is .
Edge pruning. In iteration , edge pruning is dominated by, for each vertex , identifying a center in and testing the pruning condition on all outgoing edges of . As is independent of , we have
using Lemma 4.3. Summing over all iterations yields a total expected pruning time of .
Combining the two parts gives an overall expected running time of .
5 Combining Pivots and Centers for a Faster 3-Approximation
In this section we prove Theorem 1.4. The algorithm combines the two mechanisms developed in the previous sections: the pivot machinery of the 3-APSP oracle, and the center-based sparsification used for the 4-APSP. The goal is to retain the same one-way guarantee as in Theorem 1.1, namely
for every ordered pair , while running the expensive truncated-search phase on a sparser graph.
Recall the bottleneck in the basic pivot-based algorithm. If the sampling process reaches density about , then the relevant truncated Dijkstra tree for a vertex has expected size roughly . The searches from the sampled pivots cost . The second phase is the bottleneck: even though the truncated search from a vertex visits only about vertices, it is still performed in the original graph. Under the degree-balancing assumption, the total cost of these searches is roughly
Balancing the two terms gives the choice , and hence the running time .
Our improvement is to stop the sampling earlier, at , and to sparsify the graph only once between the sampling process and the truncated searches. With this choice, the truncated balls have expected size . If the sparsification reduces the residual outdegree of every vertex to , then a truncated search that visits vertices scans only edges. Thus all final searches together cost
instead of .
The main question is how to use the sparsification procedure, which previously yielded a 4-approximation, to obtain a 3-approximation. Recall what can go wrong. The procedure may delete an edge on a shortest path and thereby obtain a good estimate for this direction (see (2)), while the shortest path remains intact and no good estimate for it is stored. If we wait until an edge on is later deleted, the original path may already have been destroyed, and the resulting estimate need not be good. This is why the 4-APSP algorithm stores a roundtrip estimate for as soon as the first edge of the roundtrip is deleted.
We also cannot run the 3-APSP oracle on a sparsified graph. Instead, in the first phase, for each vertex , we construct two sets in parallel: a pivot set , as in the basic 3-approximation oracle, and a center set .
The center set is used in the second phase to sparsify the graph in one shot. For every vertex , the algorithm inspects the outgoing edges of and deletes every edge that has a good replacement through one of the centers in . After this sparsification step, every shortest path from to satisfies one of two alternatives: either the path remains entirely in the sparsified graph , or some edge on the path was deleted. In the latter case, the path , where is the center responsible for deleting , serves as an estimate for the distance .
The pivot set has the same role as in the 3-APSP oracle, except that the final truncated Dijkstra search is run on the sparsified graph . Thus, in the third phase, if a shortest path remains in , then either the truncated search from reaches , in which case the algorithm stores the


, but

(a) The shortest path is destroyed in the sparsification.
(b) The path survives, but the truncated search stops early.
(c) The path survives and is fully explored.
Figure 3: The three cases in the proof of the fast 3-APSP algorithm. Let . If is not fully contained in , then some deleted edge on is estimated by a center ; the local replacement implies that the algorithm may use the path (left). If but , then a pivot estimates the pair (middle). If , then the truncated search stores the exact distance (right).
exact distance , or the search is stopped before reaching u. In the latter case, as in the first 3-APSP algorithm, some pivot provides a good approximation for .
5.1 Construction Overview
We now describe the algorithm proving Theorem 1.4. The algorithm maintains a subgraph , initially , and a table of directed distance estimates. For each vertex , it also maintains two sets: a pivot set , and a center set . The pivot set will be used to truncate the final searches, as in the basic 3-APSP oracle. The center set will be used to sparsify the outgoing edges of . Set
Then for , and .
Phase 1: Centers and pivots. For , the algorithm samples two sets by including each vertex independently with probability . Thus , and and are independent.
For every sampled vertex , the algorithm runs outgoing and incoming Dijkstra searches from s in the original graph G. It stores the resulting distances by setting
for every . It then uses the sampled vertices as possible proxies and updates, for every ordered pair ,
After the distances from and to have been stored, the algorithm updates the pivot and center sets. For the pivot set, for every , if there exists such that
then one such vertex is added to . This is the same update rule as in the basic pivot oracle.
The center set is updated similarly, but only using sampled outgoing neighbors. Namely, if there exists such that
then one such vertex is added to . Centers are local: every center in is an outgoing neighbor of .
Phase 2: Sparsification. After the sampling phase, the algorithm sparsifies in one shot. For every edge , it checks whether there exists a center such that
If so, the edge is deleted from .
The role of this step is twofold. First, it reduces the outdegree of the residual graph . Second, if an edge on a shortest path from to is deleted, then the path , where is the center responsible for the deletion, gives a good approximation for . Since distances through every sampled vertex were already aggregated into , this estimate is already stored.
Phase 3: Truncated searches on . Finally, for every vertex , the algorithm runs an outgoing Dijkstra search from in the sparse graph , truncated by the pivot set . When a vertex is extracted from the priority queue, let denote its current distance label. The algorithm scans the outgoing edges of only if, for every ,
Let be the resulting truncated shortest-path tree. For every , the algorithm stores the distance found by the search: .
The output estimates are the values for all ordered pairs. The construction is given in Algorithm 4.
Algorithm 4: Construction of a 3-APSP
1 Input: Directed graph with
2 Output: A table of one-way estimates.
3 Set , .
4 Set , for each .
5 Phase 1: Centers and pivots
6 for to do
7 Sample by including each vertex independently with probability .
8 Run outgoing and incoming Dijkstra from each in
9 Set , for every and
10 Set for each
11 foreach do
12 if such that
then
13 Add one such to .
14 if such that
then
15 Add one such to .
16 Phase 2: Sparsify
17 foreach do
18 foreach do
19 if such that
then
20 Delete from .
21 Phase 3: Truncated searches on
22 foreach do
23 Run outgoing Dijkstra from on ; when a vertex with current distance label is extracted, scan its outgoing edges only if
Let the resulting truncated tree be .
24 Set for all
25 return .
5.2 Analysis
We start by analyzing the stretch.
Lemma 5.1. Let . The output provides
Proof. Let be the path from v to u in G. We consider three cases (see figure 3).
Case 1: If (see figure 2 in Section 4).
This means that there was some edge that got eliminated during the second phase, by some center . So we know that
But this naturally extends to :
During the first phase, the algorithm stored
Case 2: If but (see figure 4 in Appendix A).
This means that there was a vertex and a pivot such that
Since and as , we have
and this extends to :
During the first phase, the algorithm stored
Case 3: If , so .
Next, we analyze the running time. We first record two consequences of the sparsification and truncation analyses. The first is analogous to Lemma 4.3.
Lemma 5.2. After the second phase ends, for every ,
The second is analogous to Lemma A.3.
Lemma 5.3. For every ,
We can now bound the running time.
Lemma 5.4. Algorithm 4 takes time in expectation.
Proof. We analyze the three phases separately. In the first phase, the algorithm runs incoming and outgoing Dijkstra searches from every sampled vertex. Since
this costs . In addition, for every sampled vertex , the algorithm updates all ordered pairs using the approximation . This costs
in expectation. Thus the first phase takes time.
The second phase scans the edges of and checks the deletion condition against the centers of the tail vertex. Since each center set has logarithmic size in expectation, this phase takes time.
Finally, in the third phase we run a truncated Dijkstra search from every vertex in . Since , the number of edges scanned by the search from is at most
The set depends only on the pivot samples , whereas depends only on the independent center samples . Hence,
where we used Lemmas 5.2 and 5.3. Thus, one truncated search costs in expectation, and all searches together cost . Overall, the expected running time is .
5.3 Generalizing the algorithm
In the previous algorithm, we showed how to compute a stretch-3 APSP approximation in time. This running time results from balancing the first phase, where we update the estimates for all ordered pairs through sampled vertices, with the third phase, where we run the final truncated searches on the sparsified graph.
Let us first restate this balance. Suppose that the algorithm samples vertices, and uses them as centers and as pivots. Then, by Lemmas 5.2 and 5.3, for every ,
in expectation. The first phase takes time: the term is for the Dijkstra searches from and to the sampled vertices, and the term is for updating all ordered pairs through the sampled vertices. The third phase takes
time. Substituting gives the -time algorithm.
When , the Dijkstra part in the first phase becomes smaller than the all-pairs update term . This suggests using different sampling rates for centers and pivots. The values
need to be computed only in Case 1 of Lemma 5.1, when a shortest path is destroyed by the sparsification and is the center in charge of a deleted edge on that path. The pivots, on the other hand, are needed only in Case 2 of Lemma 5.1, when the shortest path survives in but the truncated search stops before reaching .
We therefore stop sampling centers earlier than we stop sampling pivots. Let the algorithm sample pivots up to size , and let it stop sampling centers at size , where . We compute the all-pairs estimates through sampled centers only. After the truncated searches, for every , we also update
Since , this takes time.
With these parameters, the first phase takes
time. The term is the cost of the Dijkstra searches from and to all sampled pivots, while the term is the cost of updating all ordered pairs through the sampled centers.
The sparsification bound of Lemma 5.2 depends only on the centers. Hence, after stopping the center sampling at size , we get
in expectation for every . Since the original graph may already have average degree , the relevant residual degree bound is
Similarly, the truncated-search bound of Lemma 5.3 depends only on the pivots. Since pivot sampling continues up to size , we get
in expectation for every . Therefore, the third phase takes
time.
Altogether, the running time is
This expression already contains the previous pivot-only bound: taking and gives
It remains to optimize the regime where the sparsification improves over the original average degree. Write . In this regime,
so the third phase becomes
We balance the three main terms:
Equivalently,
From , we get
Combining this with gives
The resulting running time is
The condition that the sparsification improves over the original average degree is
or equivalently . Substituting , this holds exactly when , that is, when . For , the choice and gives the better bound .
We conclude that the generalized algorithm runs in
time. In particular, for dense graphs this is at most .
6 Lower Bounds
In this section we prove Theorems 1.5 and 1.6. Both reductions are from Boolean Matrix Multiplication (BMM). The first shows that improving the roundtrip stretch from 3 to would imply a BMM algorithm with essentially the same running time. The second shows that improving the coefficient 2 in the one-way guarantee
would also imply such an improvement for BMM, even if the reverse distance is allowed with an arbitrary constant coefficient.
Under the standard combinatorial BMM hypothesis, that for every constant , no combinatorial algorithm multiplies two Boolean matrices in time, these reductions rule out truly subcubic combinatorial algorithms for either task.
These reductions are also meaningful for algebraic algorithms. Boolean matrix multiplication can be solved in time, where , and Zwick's algebraic techniques give a -approximation for directed APSP with polynomially bounded weights in time [16]. Thus, an algorithm beating either of the two lower-bound thresholds in time would yield a BMM algorithm in time . Achieving such a bound in time would improve the current algebraic bound for BMM.
Our reductions are related in spirit to previous conditional lower bounds for directed girth approximation. Dalirrooyfard and Vassilevska Williams [23] proved, under the -Cycle Hypothesis, that no -time algorithm can achieve a -approximation for directed girth. Since the directed girth is the minimum nonzero roundtrip distance, this also gives a corresponding -barrier for roundtrip APSP. However, this barrier is most relevant for sparse graphs: the hard instances have , and in dense graphs the resulting bound is dominated by the cubic-time regime . Here we prove a different lower bound, based directly on BMM, showing that for roundtrip APSP the stretch-3 threshold is already inherent.
6.1 Stretch below 3
Proof of Theorem 1.5. Let . We construct a directed unweighted graph with vertices and edges.
The graph has four vertex sets
For every , add the edges
For every , add the edges
If , then for some k we have . Hence
and therefore
Suppose now that . Then there is no length-2 path from to , nor from to . Any longer path from to must first go from to , return through , and then go from to again; hence it has length at least 6. Thus
where either distance may be infinite. Therefore
We conclude that any -approximation algorithm for roundtrip APSP running in time yields an algorithm for Boolean matrix multiplication running in time .
6.2 The one-way coefficient 2
We next prove that the coefficient 2 in the asymmetric one-way guarantee cannot be improved, even if the reverse distance is allowed with an arbitrary constant coefficient.
Proof of Theorem 1.6. Let , and choose an integer
Since and are constants, is a constant.
We construct a directed unweighted graph with vertices and edges. The graph has source vertices
target vertices
and middle vertices .
For each k, create vertices
Add the fixed chains
and
for every k. For every , add the edge
For every , add the edge
Thus, every witness with gives a path
of length .
Finally, add all reverse edges
Therefore
We claim that
whereas
The first implication follows from the product path. For the second, suppose . Then there is no length-2 product path from to . Any longer path from to must first reach some target , use a reverse edge , and then reach again. This costs at least
Thus , where the distance may be infinite.
Now run the assumed algorithm. If , then
Hence
by the choice of .
If , then , and by non-underestimation,
Therefore
Reading all pairs gives the Boolean product in time .
References
[1] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms. MIT Press, 2nd edition, 2001.
[2] R. Ryan Williams. Faster All-Pairs Shortest Paths via Circuit Complexity. SIAM Journal on Computing, 47(5):1965–1985, 2018.
[3] Virginia Vassilevska Williams. Some Open Problems in Fine-Grained Complexity. SIGACT News, 49(4):29–35, 2018.
[4] D. Aingworth, C. Chekuri, P. Indyk, and R. Motwani. Fast Estimation of Diameter and Shortest Paths (Without Matrix Multiplication). SIAM Journal on Computing, 28(4):1167–1181, 1999.
[5] Dorit Dor, Shay Halperin, and Uri Zwick. All-Pairs Almost Shortest Paths. SIAM Journal on Computing, 29(5):1740–1759, 2000.
[6] Liam Roditty. New Algorithms for All Pairs Approximate Shortest Paths. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing (STOC), pages 309–320, 2023.
[7] Michal Dory, Sebastian Forster, Yael Kirkpatrick, Yasamin Nazari, Virginia Vassilevska Williams, and Tijn de Vos. Fast 2-Approximate All-Pairs Shortest Paths. In Proceedings of the 2024 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 4728–4757, 2024.
[8] Barna Saha and Christopher Ye. Faster Approximate All Pairs Shortest Paths. In Proceedings of the 2024 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 4758–4827, 2024.
[9] Edith Cohen and Uri Zwick. All-Pairs Small-Stretch Paths. Journal of Algorithms, 38(2):335–353, 2001.
[10] Surender Baswana and Telikepalli Kavitha. Faster Algorithms for All-pairs Approximate Shortest Paths in Undirected Graphs. SIAM Journal on Computing, 39(7):2865–2896, 2010.
[11] Telikepalli Kavitha. Faster Algorithms for All-Pairs Small Stretch Distances in Weighted Graphs. Algorithmica, 63(1–2):224–245, 2012.
[12] Maor Akav and Liam Roditty. A Unified Approach for All Pairs Approximate Shortest Paths in Weighted Undirected Graphs. In 29th Annual European Symposium on Algorithms (ESA 2021), volume 204 of Leibniz International Proceedings in Informatics (LIPIcs), pages 4:1–4:18, 2021.
[13] Manoj Gupta. Improved 2-Approximate Shortest Paths for close vertex pairs. In Proceedings of the 66th Annual IEEE Symposium on Foundations of Computer Science (FOCS 2025), pages 1248–1261, 2025.
[14] Ce Jin, Yael Kirkpatrick, Michal Stawarz, and Virginia Vassilevska Williams. Improved Additive Approximation Algorithms for APSP. In Proceedings of the 2026 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 3639–3651, 2026.
[15] Noga Alon, Zvi Galil, and Oded Margalit. On the Exponent of the All Pairs Shortest Path Problem. Journal of Computer and System Sciences, 54(2):255–262, 1997.
[16] Uri Zwick. All pairs shortest paths using bridging sets and rectangular matrix multiplication. J. ACM, 49(3):289–317, 2002.
[17] Liam Roditty and Asaf Shapira. All-pairs shortest paths with a sublinear additive error. ACM Trans. Algorithms, 7(4), 2011. Article 45.
[18] Michael J. Fischer and Albert R. Meyer. Boolean Matrix Multiplication and Transitive Closure. In Proceedings of the 12th Annual Symposium on Switching and Automata Theory (SWAT 1971), pages 129–131, 1971.
[19] Virginia Vassilevska Williams and R. Ryan Williams. Subcubic Equivalences Between Path, Matrix, and Triangle Problems. J. ACM, 65(5), 2018. Article 27.
[20] Lenore J. Cowen and Christopher G. Wagner. Compact roundtrip routing in directed networks (extended abstract). In Proceedings of the Nineteenth Annual ACM Symposium on Principles of Distributed Computing, PODC '00, pages 51–59, New York, NY, USA, 2000. Association for Computing Machinery.
[21] Liam Roditty, Mikkel Thorup, and Uri Zwick. Roundtrip spanners and roundtrip routing in directed graphs. ACM Trans. Algorithms, 4(3), 2008. Article 29.
[22] Shiri Chechik, Yang P. Liu, Omer Rotem, and Aaron Sidford. Constant girth approximation for directed graphs in subquadratic time. In Proceedings of the 52nd Annual ACM SIGACT Symposium on Theory of Computing (STOC 2020), pages 1010–1023, 2020.
[23] Mina Dalirrooyfard and Virginia Vassilevska Williams. Conditionally optimal approximation algorithms for the girth of a directed graph. In 47th International Colloquium on Automata, Languages, and Programming (ICALP 2020), volume 168 of Leibniz International Proceedings in Informatics (LIPIcs), pages 35:1–35:20, 2020.
[24] Shiri Chechik and Gur Lifshitz. Optimal girth approximation for dense directed graphs. In Proceedings of the Thirty-Second Annual ACM-SIAM Symposium on Discrete Algorithms, SODA '21, pages 290–300, USA, 2021. Society for Industrial and Applied Mathematics.
[25] Alina Harbuzova, Ce Jin, Virginia Vassilevska Williams, and Zixuan Xu. Improved Roundtrip Spanners, Emulators, and Directed Girth Approximation. In Proceedings of the 2024 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 4641–4669, 2024.
[26] Jakub Pachocki, Liam Roditty, Aaron Sidford, Roei Tov, and Virginia Vassilevska Williams. Approximating Cycles in Directed Graphs: Fast Algorithms for Girth and Roundtrip Spanners. In Proceedings of the 2018 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 1374–1392, 2018.
[27] Ruoxu Cen, Ran Duan, and Yong Gu. Roundtrip Spanners with (2k-1) Stretch. In 47th International Colloquium on Automata, Languages, and Programming (ICALP 2020), volume 168 of Leibniz International Proceedings in Informatics (LIPIcs), pages 24:1–24:11, 2020.
[28] Josh Alman, Ran Duan, Virginia Vassilevska Williams, Yinzhan Xu, Zixuan Xu, and Renfei Zhou. More Asymmetry Yields Faster Matrix Multiplication. In Proceedings of the 2025 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 2005–2039, 2025.
A 3-Roundtrip Distance Oracle: Analysis
In this appendix, we provide the full analysis of Algorithm 1. We begin by analyzing the stretch guarantee of the oracle.
Lemma A.1. For any ,
Proof. Fix any query , and let be a shortest path from to in . The oracle returns
If all vertices of are explored by the truncated Dijkstra search from , then and therefore . So,
as . Otherwise, let be the first vertex on (closest to ) that is not relaxed during the truncated search. By definition of the truncation predicate, there exists a pivot such that
Add to both sides of (8):
By the triangle inequality,
(A)
(B)
Hence
by (A)
by (8)
by (B)
Since lies on a shortest path, , and therefore
and the inequality naturally extends from x to u, see Figure 4.
Subtracting from both sides yields
Therefore,
Next, we bound the expected size stored in the oracle. To do so, we first bound the expected size of for every v.

Figure 4: An illustration of the bypass intuition underlying Inequality 9. When the truncation condition fails at vertex (Inequality 8), the path from to (purple) is conceptually rerouted via the pivot , following a path of the form (green).
Definition A.2 (Eligible pivots). Fix . For each iteration , let be the pivot set of at the beginning of iteration . Define the set of eligible pivots for at iteration by
In other words, consists of the vertices that can still be selected as future pivots for after the first rounds.
At iteration , a new pivot is added to if and only if , since a sampled vertex is eligible to be chosen as a pivot for exactly when it belongs to .
Claim A.2.1. Fix . Then for all ,
Before proving the claim, observe that the truncated search tree is always a subset of , since the algorithm relaxes a vertex only if it satisfies the truncation predicate with respect to all pivots in after all iterations. Therefore, by setting and using that , Claim A.2.1 implies
Proof. Fix and , and let be the sampling probability of in iteration . Assume we are at iteration of the algorithm, so that is fixed, and we wish to bound .
Consider the complete directed graph on the vertex set defined as follows. For every unordered pair , orient the edge from to if
and otherwise orient it from y to x (breaking ties arbitrarily). Thus, this orientation defines a tournament on .
Observe that if a vertex is added to the pivot set of , then every vertex such that the edge is oriented from to is removed from the set of eligible pivots in the next iteration. Indeed, once is added to the pivot set, such a vertex no longer satisfies the defining inequality for membership in . Conversely, every vertex such that the edge is oriented from to remains in , since it still satisfies the defining inequalities for all pivots in , and also for the new pivot . Therefore, after adding , the set is exactly the set of in-neighbors of in this tournament.
In particular, if one chooses a vertex uniformly at random from , then the expected size of the resulting set is
since a tournament on vertices has exactly directed edges.
Thus, conditioning on the event , the new pivot chosen for is distributed uniformly over by symmetry: conditioned on this event, each vertex of has the same probability to be selected, since the vertices are sampled independently and the algorithm chooses uniformly among the sampled eligible vertices. Hence,
where the expectation is on the choice of .
On the other hand, if , then no new pivot is added for in iteration , and therefore
Since each vertex of is sampled independently with probability , we have
Combining the two cases by conditioning on the event , we obtain
and hence
We now convert this inequality into a recurrence. Multiplying both sides by
and using the bound
gives
Using also the standard inequality
we get
Let
Taking expectations yields
Note that , so implies by induction that
Therefore,
as claimed. Since , we also have
□
Lemma A.3. The size of the oracle is in expectation, and the preprocessing time is in expectation.
Proof. We bound the space usage and preprocessing time of each phase separately.
Phase 1. In iteration , for every sampled witness the algorithm stores the distances between and all vertices . Since and , the expected total amount of information stored in Phase 1 is
The expected running time of this phase is , dominated by the incoming and outgoing Dijkstra searches performed from all sampled witnesses .
Phase 2. For each vertex , the truncated Dijkstra search from explores a set of vertices satisfying the truncation predicate. By Claim A.2.1, we have for every . Since the oracle stores the distances for all , the total expected amount of information stored in Phase 2 is
This phase runs in expected time . For each vertex , the truncated Dijkstra search explores vertices in expectation. Assuming the maximum out-degree is , the cost of running Dijkstra restricted to is . In addition, each relaxation requires checking the truncation predicate against all pivots in , which takes time. Summing over all yields a total expected running time of .
The assumption that the maximum degree is is without loss of generality: as shown by Chechik et al. [22], any directed graph can be reduced to this case in time.
B A 5-Roundtrip APSP Approximation in
A natural question in the study of approximate APSP in directed graphs is what roundtrip approximation factor can be achieved within time, which is a fundamental lower bound imposed by the output size of the problem. While the algorithms in the previous sections achieve a small roundtrip stretch, their running times exceed this quadratic barrier.
In this section, we show that by allowing a slightly larger approximation factor, this barrier can be met up to polylogarithmic factors. Specifically, we prove Theorem 1.7 and Corollary 1.8 by constructing a 5-roundtrip distance oracle with near-quadratic preprocessing time, and showing how querying it on all vertex pairs yields a 5-APSP approximation in expected time.
At a high level, the distance oracle construction combines the center-based sparsification of Section 4 with the pivot-based truncated-search framework of Section 3. The algorithm first applies the center-sampling process, progressively removing edges while recording limited pivot information, until the remaining graph becomes sufficiently sparse. Once the number of edges drops to in expectation, the algorithm applies the 3-roundtrip oracle construction of Section 3 to the sparsified graph. The phase transition is chosen so that the second phase can be executed within the quadratic time budget. Indeed, when applied to a graph with edges, the preprocessing time of the 3-roundtrip oracle is .
B.1 Construction Overview
The construction proceeds in two phases. The first phase follows the sparsification framework of the 4-roundtrip APSP algorithm from Section 4, but replaces the expensive aggregation step by selecting a single pivot per vertex in each iteration. The second phase applies the 3-roundtrip distance oracle construction on the resulting sparse graph.
Phase 1: Sparsification with nearest pivots. The algorithm maintains a sequence of graphs , obtained by iteratively deleting edges. Initially, .
It performs
Note that for , and .
For each vertex , the algorithm maintains a set of pivots , initially empty. By the end of the first phase, .
For iterations , the following steps are executed.
Sampling pivots/centers. A set is sampled by including each vertex independently with probability . Hence .
Computing distances and selecting pivots. Let denote the current graph. For each sampled vertex , the algorithm runs both outgoing and incoming Dijkstra searches rooted at in the current graph . Then, the oracle stores these distances by setting and for all and .
For each vertex , the algorithm selects a pivot
and adds to (ties are broken arbitrarily).
This is the main departure from the 4-roundtrip APSP algorithm: instead of aggregating distances for all triples , the algorithm keeps only the nearest sampled pivot for each vertex. As a result, the running time of this step is reduced from to per iteration. We show later that this weaker aggregation still yields a sufficiently good roundtrip approximation.
Edge pruning. Edge pruning is performed exactly as in the 4-roundtrip APSP algorithm. For each vertex , let denote its outgoing neighbors in . If , a center is chosen uniformly at random. Note that is the center used for pruning the outgoing edges of , whereas is the nearest pivot to ; the two may differ.
The algorithm then inspects every edge . If has an assigned center and
the edge is deleted. Let denote the resulting graph. Note that all the distances above are stored via .
After iterations, the first phase ends, and the graph has edges in expectation.
Phase 2: Distance oracle on the sparse graph. In the second phase, the algorithm applies Algorithm 1 to the sparsified graph , as described in Section 3, and merges the pivot sets produced by that algorithm with the pivot sets maintained in Phase 1.
Distance query. Similarly to Algorithm 2, to answer a query , the oracle returns the minimum among the distances provided by the truncated tree of and by routing through the pivots of :
We summarize the construction in Algorithm 5.
Algorithm 5: Construction of a 5-roundtrip distance oracle
Input: Directed graph with non-negative weights.
Output: Distance oracle
1 ; for each ;
2 Set and ;
3 for to do
4 Sample by including each independently with probability ;
5 Run outgoing and incoming Dijkstra from each in
6 Set , for every and
7 foreach do
8 Set ;
9 Add to ;
10 ;
11 foreach such that do
12 pick a random ;
13 foreach do
14 if then
15 delete edge from ;
16 Run Algorithm 1 on and merge the pivot sets for all .
B.2 Analysis
We begin the proof of Theorem 1.7 by analyzing the stretch of the distance oracle.
Lemma B.1. For every , the distance query returns an estimate satisfying
Proof. Fix vertices , and let denote a shortest roundtrip (cycle) between and in .
If , then Algorithm 1 is applied to a graph containing the entire shortest roundtrip. As shown previously, in this case the oracle returns an estimate satisfying
which is stronger than the claimed bound.
We therefore assume that . Let be the last iteration such that . Then there exists an edge on with
The edge was removed in iteration because there exists a vertex such that
Exactly as in the proof of Lemma 4.2, one can show that (3) holds (see Figure 2):
By definition, the pivot is chosen to be at least as close to as , and hence
The oracle therefore routes from to via the pivot , yielding
as claimed.
Next, we analyze the size of the oracle and the preprocessing time.
Lemma B.2. The oracle stores expected data and is constructed in expected time .
Proof. We analyze the two phases separately. For the second phase, the bounds follow directly from Lemma A.3, applied to the graph . By Lemma 4.3, we have , and since the same edge-pruning procedure is used here, the analysis carries over without modification.
It therefore remains to bound the space usage and running time of the first phase. In this phase, the oracle stores distances computed by running Dijkstra from all sampled centers in . Thus, the space usage is proportional to the total number of sampled centers, and the running time is dominated by the corresponding Dijkstra executions.
Since and , we have
The expected space usage of the first phase is . Moreover, is independent of , so by Lemma 4.3,
Summing over all iterations, the expected time for the Dijkstra computations is .
In addition, in each iteration and for each vertex , the algorithm computes in order to select a pivot. This requires time per iteration, and therefore contributes a total expected time of over all iterations.
C Using FMM to Accelerate the Algorithms
Min-Plus Product We begin by formalizing the min-plus product.
Definition C.1 (Min-plus matrix product). Let and . Their min-plus product is the matrix defined by
We denote by the algebraic exponent for multiplying an matrix by an matrix in time. We use the following standard black box: combining Zwick's scaling-based -approximate distance-product framework [16] with bounds for rectangular matrix multiplication (see, e.g., [28]), one can compute a one-sided -approximate rectangular min-plus product of an matrix and an matrix, whose finite entries lie in , in time
That is, if is the computed approximation to , then
for every . Zero and infinite entries can be handled separately in the standard way.
C.1 -APSP
The fully combinatorial algorithm of Section 4 spends time in iteration i to compute
by explicit enumeration over . This is the bottleneck in the aggregation step of the sparsification procedure.
To accelerate this aggregation, assume that for every , and fix . Let
so that is an matrix. Since roundtrip distance is symmetric, the desired values are given by the min-plus product . We replace the explicit enumeration by a -approximate rectangular min-plus product . The finite entries of lie in , apart from zero diagonal entries, which are handled separately. Thus, for every ,
The remainder of the algorithm—sampling, Dijkstra computations, and edge pruning—is unchanged.
Suppose that the shortest roundtrip between v and u is destroyed by the sparsification. By Lemma 4.2, for some iteration i,
Consequently,
If the shortest roundtrip survives in the final graph , the 3-approximation algorithm run on gives a valid -approximation. Hence the resulting approximation guarantee is .
Since the sizes of the sets grow geometrically and are at most , the total time for all approximate min-plus products is
All other work in the sparsification procedure takes expected time. Moreover,
and therefore running the 3-approximation algorithm on H takes
expected time.
The total expected running time is therefore
Choosing so that
and using the current bounds for rectangular matrix multiplication gives the stated
running time.
C.2 -APSP
As in Section C.1, we accelerate the aggregation through the sampled vertices. Here, we retain the exact incoming and outgoing Dijkstra searches from the sampled vertices, and accelerate only the all-pairs aggregation.
We use the algorithm of Section 5 with a single sampling exponent . As in that section, centers and pivots are sampled independently, with sampled vertices of each type. Let
For every , we run incoming and outgoing Dijkstra searches in the original graph , computing
for every . This takes time. Since all distances used in the pivot and center comparisons are exact, the size analysis of Section 5 remains unchanged. Thus, for every ,
The all-pairs proxy values through the sampled centers are computed using a -approximate rectangular min-plus product, as in Section C.1. For the pivots, instead of aggregating through all sampled vertices, we update, for every ,
Since , these updates take time. The final truncated searches are unchanged.
We now analyze the approximation error. As in Lemma 5.1, consider a shortest path from to . If the path is destroyed by sparsification, some sampled center satisfies
The approximate min-plus product therefore gives
If the path survives but the truncated search stops, a pivot in provides the same bound without the additional approximation factor. Otherwise, the exact distance is found. Consequently,
The Dijkstra searches take time, while the approximate min-plus product takes
time. The final truncated searches take
Thus, the total expected running time is
Let satisfy
using the current bounds for rectangular matrix multiplication (see, e.g., [28]). We choose
If , then , and all three terms are bounded by . Otherwise, , and the Dijkstra searches and truncated searches both take time. Since , the matrix multiplication term is dominated by this bound.
We therefore obtain a -approximation in expected time
For , Corollary 1.2 already gives a stretch-3 approximation in time.