New Diameter Approximations via Distance Oracle Techniques
Abstract
Computing the diameter of a graph is a problem of great interest both in general algorithms research and specifically within fine-grained complexity, where it is a cornerstone hard problem. As computing the exact diameter in -edge graphs requires time under the Strong Exponential Time Hypothesis, much work has gone into approximating this parameter. Recent work has achieved a full conditional lower bound tradeoff curve for both directed and undirected graphs [Dalirrooyfard, Li and Vassilevska W., FOCS’21]. However, the best known upper bounds do not match the lower bounds. In particular, the best known approximation scheme for undirected graph diameter [Cairo-Grossi-Rizzi, SODA 2016] has not been improved. Moreover, this scheme is randomized and no similar deterministic scheme is known.
Another fundamental field of research in shortest paths computation is the construction of approximate distance oracles. Thorup and Zwick [JACM’05] provided the first such distance oracle with constant query time and (conditionally) optimal space, and in the years since many advances have led to a vast toolbox of techniques and data structures.
These two areas of research seem natural to combine since they both concern approximating shortest paths. However, the known diameter approximation algorithms only use a small subset of the techniques used in distance oracles research. In this work we show that in fact approximate diameter and distance oracles are intricately connected.
We first demonstrate a strong connection between the current best known diameter approximation scheme of Cairo, Grossi and Rizzi (“CGR”) and the -approximate distance oracle of Thorup and Zwick. This allows us to derandomize the CGR algorithm and obtain the first deterministic diameter approximation tradeoff.
We further derandomize other central techniques in the field of distance oracles and use them to achieve new deterministic diameter approximation algorithms, including a simpler -approximation with no additive error and a new -approximation, the first new step in the diameter approximation tradeoff in almost a decade. Finally, we show how these new techniques can be used to derandomize many current best known results in various fields of shortest paths approximations.
Keywords and phrases:
Graph Algorithms, Diameter, Distance Oracle, Approximation AlgorithmCategory:
Track A: Algorithms, Complexity and GamesFunding:
Yael Kirkpatrick: Supported by NSF Grant No 2141064.Copyright and License:
2012 ACM Subject Classification:
Theory of computation Graph algorithms analysisEditors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele PuppisSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
One of the most fascinating problems in shortest paths algorithms is estimating the diameter of a given graph. The diameter is the largest shortest path distance and is a natural parameter that measures how fast information can spread in a network. Computing the diameter can be accomplished by first computing All-Pairs Shortest Paths (APSP), going through all computed distances and returning the largest. This approach is largely unsatisfying because the output size of APSP in -node graphs is and hence even in very sparse graphs, one cannot hope to obtain sub- time algorithms for the diameter if one first computes APSP. The situation is even worse in dense weighted graphs, where the fastest exact algorithm for APSP runs in time [41]. The fastest approximation algorithms use fast matrix multiplication: Zwick [43] provided an time 111 subsumes polylogarithmic factors. -approximation algorithm where is the exponent of square matrix multiplication [7]. (Boolean) matrix multiplication is also known [25] to be necessary for any finite directed (or factor undirected) approximation algorithm for APSP.
It remains a big open problem whether computing the diameter of a graph exactly requires computing APSP. Roditty and Vassilevska W. [37] showed that the Strong Exponential Time Hypothesis (SETH) ([28, 13]) implies that computing the exact diameter requires time in sparse graphs. Because of this, a lot of research has focused on obtaining fast, subquadratic time approximation algorithms.
Aingworth, Chekuri, Indyk and Motwani [5] gave an time deterministic algorithm that achieves an “almost” approximation222Here “almost” means that there is extra small additive error, in addition to the multiplicative approximation factor.: an estimate of the diameter such that in any directed or undirected graph with nonnegative integer edge weights bounded by . Roditty and Vassilevska W. [37] obtained the same guarantees as [5] but with improved (expected) running time at the cost of randomization.
Cairo, Grossi and Rizzi [12] extended the techniques of [37, 5] to obtain a runtime/approximation tradeoff for undirected graphs. For every , they construct an algorithm with expected running time achieving , an almost -approximation. We call this approximation scheme “CGR”. Abboud et al. [3] obtain a weaker scheme for directed graphs.
Chechik et al. [15] removed the additive error in the almost -approximation algorithm of [37] at the cost of higher running time . Backurs et al. [8] provide an almost- approximation and an time almost- approximation with better additive error.
All known diameter approximation algorithms except for the original Aingworth et al. [5] algorithm and the time algorithm of [15] are randomized. This raises our first natural question:
Question 1: Can one obtain deterministic diameter approximation algorithms with the same guarantees as the known randomized algorithms?
Another important area of research in APSP approximation for undirected graphs is the construction of space-efficient approximate distance oracles that answer distance queries in constant time. Thorup and Zwick [40] first provided a randomized construction that for every integer and every undirected -node -edge graph with nonnegative weights preprocessed a distance oracle in expected time that could provide a -approximation to any distance in query time. Later, Roditty, Thorup and Zwick [36] derandomized the construction. Chechik [14], following Wulff-Nilsen [42], brought down the query time to a global constant, independent of .
The space usage of these oracles is known to be optimal under the Erdös Girth Conjecture. Recent work [2, 1, 29] has focused on showing that the preprocessing time of the distance oracles might be optimal. The latest of these results is that under the SUM Hypothesis, time is needed to compute any -distance oracle of an -edge graph that can support time queries.
The literature on distance oracles is vast and there is a huge toolbox of techniques for constructing them. By and large, the known diameter approximation algorithms use a very small subset of the techniques for distance approximation: mainly hitting sets of balls around vertices, combined with Dijkstra’s algorithm. Moreover, there are many different constructions of distance oracles (with different guarantees) besides the original Thorup and Zwick construction: e.g. [6, 34, 33]. Meanwhile, there are only a small handful of diameter approximation algorithms, the main one being the Cairo-Grossi-Rizzi construction (which itself is based on [5, 37]). Here we ask:
Question 2: Can we obtain new diameter algorithms by employing the vast techniques from the distance oracle literature? Can the many known distance oracle constructions lead to new diameter algorithms?
1.1 Our results
In this paper we establish a strong connection between distance oracles and diameter approximations, which allows us to address both Question 1 and Question 2.
We first employ a classic deterministic distance oracle construction to obtain a diameter approximation algorithm matching the tradeoff curve of Cairo, Grossi and Rizzi. Beyond derandomization, this new algorithm is a simpler version of the longstanding state of the art diameter approximation and the first improvement over it in almost a decade.
We further develop tools to derandomize other known diameter approximations, showing that randomization is not needed in most of the current best known diameter approximation algorithms. Additionally, we leverage other existing distance oracles to obtain new diameter approximation algorithms.
While this work takes only a small step towards closing the gap between the best known upper and lower bounds for diameter approximations, we hope the powerful connection we demonstrate between distance oracles and diameter approximations will open the door to new advancements in this field using the extensive range of techniques used in approximate distance oracles.
1.2 Derandomization of Diameter Algorithms
Our first result is a full derandomization of the Cairo-Grossi-Rizzi (CGR) [12] approximation scheme for diameter in undirected graphs. We show how to achieve this best known runtime/approximation tradeoff using the classic -approximate distance oracle structure of Thorup and Zwick [40], which in turns allows us to use the subsequent derandomization of this distance oracle to derandomize our diameter approximation scheme.
Theorem 1 (Theorem 11 in the body).
Given an undirected graph with nonnegative edge weights bounded by and an integer , one can compute in deterministic time an estimate of the diameter satisfying where .
We note that our deterministic algorithm runs in the exact same time as the original algorithm of [12], without adding any logarithmic factors to the runtime, which is often the cost of derandomizations. Furthermore, our algorithm also derandomizes the radius and eccentricity approximation schemes of [12]. While there is an expected time -approximation algorithm for all eccentricities [17, 8] which subsumes the CGR eccentricities scheme, it is not known how to derandomize these -approximation algorithms. Thus, our derandomization of CGR presents the best known deterministic approximation algorithms for all nodes eccentricities.
Our next contribution is a derandomization of another tool frequently used in distance oracles: the computation of clusters and balls that are simultaneously small, first introduced by Thorup and Zwick [39]. For a vertex and a set of vertices , the -ball of , is the set . The -cluster is . If the graph is directed, we can define and to be and in the graph with edge directions reversed.
Clusters and balls are in a sense inverses of each other. The fast computation of small clusters and balls is at the heart of fast distance oracle preprocessing. Approximate distance oracles often use a random resampling technique to construct a set with worst case guarantees on the size of all of its clusters (this technique originates from [39]). Here, we show that the same can be achieved deterministically in the same time complexity.
Theorem 2.
Given a weighted, directed or undirected graph and , one can compute a set of size deterministically in time such that for every , .
1.3 New Diameter Approximation Algorithms from Known Distance Oracles
Using this new deterministic tool, together with ideas from two known distance oracle constructions, we obtain new deterministic diameter approximation algorithms.
The first result we address concerns removing the additive error from the original -diameter approximation of Aingworth et al. [5]. Chechik et al. [15] gave a time deterministic -approximation to the diameter of any directed or undirected graph, getting rid of the additive error at the cost of a slower runtime.
Using the tools from a distance oracle data structure [34], combined with our deterministic cluster and ball computation tool, we obtain an arguably simpler algorithm that achieves roughly the same result as [15], and even removes a logarithmic factor in the running time.
Theorem 3 (Theorem 18 in the body).
Given a directed graph with nonnegative edge weights and (unknown) diameter , one can compute in deterministic time an estimate satisfying .
We then combine the basis of the distance oracle of [6] with our new deterministic tools to obtain a brand new diameter approximation algorithm, the first such algorithm whose multiplicative approximation is not of the form .
Theorem 4 (Theorem 19 in the body).
Given an unweighted, undirected graph with (unknown) diameter , one can compute in deterministic time an estimate satisfying for .
This almost- approximation algorithm is faster than all the known almost--diameter approximation algorithms (which run in time) for every graph density in the interval .
Notice that the approximation guarantee is between the and guarantees of the CGR algorithm [12] for and respectively, so that this is a brand new point on the trade-off curve for diameter approximation algorithms.
Over the last decade, there has been significant progress in fine-grained conditional lower bounds for diameter. Starting with the work of [37, 8, 11] and culminating in the results of [32, 23, 20], we now have a full lower bound trade-off curve for diameter even in undirected and unweighted graphs: under the Strong Exponential Time Hypothesis, for every integer , any approximation algorithm needs time. Using , we get that the -approximation algorithms of [37, 15] are optimal under SETH, and using in the limit, we get that the folklore linear time -approximation cannot be improved.
If we believe that the known conditional lower bounds are best possible, we should suspect that (for in the trade-off) there should be a -approximation algorithm running in time. Unfortunately, the known time approximation algorithm on the CGR curve [12] only achieves a approximation. Our new -approximation algorithm can be seen as a step towards the desired next algorithmic point on the lower bound curve after .
1.4 Applications and Further Derandomizations
To illustrate the usefulness of our new techniques, we obtain derandomizations of several known results related to various problems in the field of shortest path computations.
First we consider the APSP approximations of Baswana and Kavitha [9]. They construct a -approximation and a -approximation algorithm using a hierarchy of randomly sampled sets and a randomized version of Theorem 2. This randomized hierarchy needs to satisfy two conditions. First, that for every set of size the set of edges defined as the edges incident to of weight satisfies . This can be achieved deterministically by constructing a greedy hitting set to the highest weight incident edges of every vertex, which can be done in time. Second, the hierarchy of sets needs to satisfy that for every vertex , , which can be achieved using the deterministic distance oracle construction of Roditty, Thorup and Zwick [36]. Taking the sets obtained the construction of [36], and taking a union of each with a hitting set to the highest weight incident edges of every vertex guarantees that both conditions hold. Together with Theorem 2, this gives us a deterministic version of the following result:
Theorem 5 (Derandomization of Algorithms 9 and 10 in [9]).
A given weighted undirected graph on vertices can compute all-pairs -approximate distance in deterministic time or all pairs -approximate distance in deterministic time .
Using a similar idea, we can derandomize the -time construction of a -approximate distance oracle of Baswana and Kavitha [9]. In this algorithm, they use a similar hierarchy of sets of sizes which satisfy the same properties. To avoid the runtime, they authors construct a -spanner on edges and use it to construct a graph on in expected linear time. They proceed to compute -balls using only the edges of this graph and compute the sets for every vertex in quadratic time.
We can derandomize this algorithm by beginning with sets which are deterministic hitting sets to the highest weight edges adjacent to every vertex. We can then compute the same -spanner in deterministic linear time [36] and compute the closest vertices to each vertex in the corresponding subgraph in time . We take to be the union of deterministic hitting set to these neighborhoods and . For subsequent ’s, we compute for every vertex in the graph . We then take to be the union of and a deterministic hitting set of all . This approach gives us the following deterministic result:
Theorem 6 (Derandomization of Theorem 6.6 of [9]).
An undirected, weighted graph on vertices and edges can be preprocessed in deterministic time to compute a -distance oracle of size for any integer .
Because Theorem 2 is a direct derandomization of Corollary 3.3 from [39], we also get a deterministic version of their algorithm for constructing a stretch routing scheme that works in the same time complexity (note that their scheme cites a deterministic construction of a 2-level hash table that supports lookups in worst-case constant time).
Backurs et al. [8]333We note that Theorem 38 of [8] (a randomized algorithm that yields a slightly better almost- diameter approximation and almost- eccentricity approximation for undirected, unweighted graphs) can directly be derandomized using the deterministic distance oracle techniques from [36]. use the randomized small clusters technique from [39] to obtain an almost- approximation of undirected unweighted diameter in expected time. The randomness in their algorithm arises from randomly sampling a hitting set of size such that for all . Then, the algorithm iterates over all pairs of vertices within every cluster, resulting in an contribution in time complexity. The algorithm also uses a result from Knudsen [31] to obtain an additive spanner with edges in deterministic time, and computes shortest path threes in in time.
To derandomize the result, we first compute the nearest neighbors to each node, which can been listed out in time (see the construction of a k-partial-BFS tree in [25]). Then, we use our Lemma 16 to compute the hitting set with the same guarantees in deterministic time, giving us the following result:
Theorem 7 (Derandomization of Algorithm 32 in [8]).
There is a deterministic time algorithm that, for an unweighted undirected graph with diameter where is a positive integer and , outputs a value satisfying
1.5 Related work
Besides the typical definition of diameter, there are several other notions of diameter in directed graphs, using different symmetric notions of distance ([4]). Several works [4, 16, 10, 22, 19] provide approximation algorithms for the so-called min-diameter which is defined as . The roundtrip diameter is , and approximation algorithms and conditional lower bounds for it were studied by [3, 4]. Other notions such as diameter and bichromatic diameter were studied by [8, 21]. Most of the known algorithms are randomized. We suspect that at least some of them can be derandomized using our techniques.
There is a lot of work on APSP approximation. Besides the approximation algorithms mentioned so far, there is work on additive approximations for APSP [25, 24, 27, 38] and multiplicative -approximations [5, 25, 18, 9, 30, 24, 27, 35, 26, 38]. We can’t hope to capture all of the vast literature on shortest paths approximation. We invite the reader to look at the references in the above papers for more.
2 Preliminaries
Let be a directed or undirected graph on vertices and edges. When is a weighted graph denote by the weight of the edge . Given a pair of vertices denote by the length of the shortest path from to in . When is clear from context we drop the subscript.
Denote by the eccentricity of a vertex and let be the diameter of the graph and be the radius of the graph.
We say that a value is an -approximation to a parameter if . When we have a multiplicative approximation and call it an -approximation. When is a constant we refer to as an “almost” -approximation.
Given a vertex , denote by its neighborhood. Given an additional set define the -ball of a vertex by . Define the -cluster as . In some case we are interested in the neighborhood of the -ball of a vertex, we denote this set by .
If is a directed graph, we further define the incoming -balls and clusters to be the -balls and clusters in the graph with edge direction reversed.
Given a subset , and integer , for the set is defined to be the closest vertices of to , i.e. and whenever , then . When creating , ties are broken according to some permutation of the vertices, e.g. the lexicographic order of their names.
We use the following result concerning the fast, deterministic computation of the sets .
Lemma 8 (Theorem 2 of [36]).
For any directed -node, -edge with positive edge weights, any , , one can compute for all in time deterministically by performing SSSP444Single source shortest paths, either BFS in time in undirected graphs or Dijkstra’s algorithm in time in directed graphs. We make this distinction since in some cases we wish to be careful about our log factors. computations on graphs with nodes and edges.
Another fundamental tool we use is the construction of a deterministic hitting set:
Lemma 9 (Greedy hitting set).
Given such that and for all , , one can compute deterministically in time a set of size such that for all , .
As mentioned, we derandomize a stronger variant of the balls and clusters construction, one that guarantees that the clusters of all vertices are of bounded size. The proof of this theorem can be found in Section 4.
Theorem 2. [Restated, see original statement.]
Given a weighted, directed or undirected graph and , one can compute a set of size deterministically in time such that for every , .
In such a setting, when all vertices have small clusters, we note that in time we can compute not only for all vertices but also , where represents the time it takes to compute a single graph SSSP search. We can do this by scanning the edges out of every and using the following claim.
Claim 10.
.
Proof.
3 Deterministic -Diameter Approximation
In this section we derandomize the longstanding best known diameter approximation tradeoff of Cairo, Grossi and Rizzi [12], achieving a deterministic algorithm that matches the multiplicative and additive approximation guarantees of [12] without incurring any additional cost on the runtime (as our algorithm matches the runtime of [12] down to the logarithmic dependency). To do so, we avoid randomized sampling techniques and reduce the problem of approximating the graph diameter to a series of queries to the classic approximate distance oracle of Thorup and Zwick [40]. Using the deterministic construction of this distance oracle of Roditty, Thorup and Zwick [36], we obtain the first deterministic diameter approximation tradeoff for undirected graphs.
Just as the algorithm of Cairo, Grossi and Rizzi also provides a -approximation to the graph radius and a -approximation to all eccentricities, so can our algorithm. We defer the proof of this result to Section 6.
We note that by using Lemma 9 to construct a hitting set of neighborhoods constructed using Lemma 8, we can easily derandomize both the time almost- approximation of [37] and the time genuine- approximation of [15] which work in directed graphs. Derandomizing the full CGR construction is not as simple since the original randomized construction uses random samples to hit large node neighborhoods that would be expensive to construct explicitly. We get around this by adapting the ideas behind the Thorup-Zwick distance oracles.
Theorem 11.
Given an undirected graph with edges weight bounded by and an integer , one can compute in deterministic time an estimate satisfying where .
Proof.
We begin by recursively constructing the data structure used in the deterministic -approximate distance oracle of [36]. Begin with . Now, assuming we have the set , let be the closest vertices to in , we will set the exact logarithmic dependency of in our runtime analysis. Using Lemma 8, we can construct these sets in time. Define to be a greedy hitting set of the sets for all using Lemma 9. Note that the lemma gives the following property:
Claim 12.
.
For every , run Dijkstra’s algorithm from the set and let be the furthest vertex of from the set. Define . By the definition of , .
Finally, we run Dijkstra’s algorithm from and from every vertex for and return the largest distance found. See Algorithm 1 for the full pseudo-code.
Correctness.
We want to show that the distance returned by the algorithm satisfies the desired distance approximation. Clearly as it is a true distance in the graph, so we are left to show the lower bound. To do so we define a series of parameters and use them to prove that at every step either we find a pair of vertices of distance or the vertex is sufficiently far from and we proceed inductively.
Fix a pair of diameter endpoints, and define the values as follows. Let , we want to show that . For every define . Finally, define for every .
Note that since the ’s are increasing we always have that . Furthermore, so all . Next we note the following property relating our chosen parameters to each other and motivating their definition.
Proposition 13.
.
Proof.
Thus, .
We wish to show inductively that at every step of the algorithm we either find a pair of point far enough apart or claim a lower bound on the distance between and . We begin with the base case.
Claim 14.
If there exists a vertex such that then .
The proof follows from the triangle inequality. Thus, if after running Dijkstra’s from we don’t have a good enough approximation then .
Lemma 15.
Suppose , then after running Dijkstra’s from we either have an estimate , or .
Proof.
When we run Dijkstra’s from , if we do not get the desired approximation we must have that . Since , the set contains all vertices of at distance from .
Consider the shortest path between and . There must exists a vertex on this shortest path such that and
Consider the distance . If this distance is greater than then we have that . Otherwise, there exists such that . So by the triangle inequality,
Therefore, and so we have computed Dijkstra’s from it. Furthermore, by Proposition 13,
Meaning and we have computed the desired approximation. We conclude that after running Dijkstra’s from either is sufficiently large or .
By applying Lemma 15 times, using Claim 14 as the base case, we either compute an estimate or have that .
In this case, contains all vertices of at distance from . Since we run Dijkstra’s from we can assume or we have already found a sufficiently large distance. Thus, there exists a vertex on the shortest path between and such that and
Therefore and and so running Dijkstra’s from all vertices in gives us the desired approximation. We conclude that,
Runtime.
Using Lemma 8, we can compute the sets in total time where is the time it takes to run a single graph search. Next, using Lemma 9, computing takes time and produces a set of size . Finding and computing can be done in time and running Dijkstra’s algorithm from every takes as .
Thus, running lines 5-9 takes time, for a total runtime of . Finally, running Dijkstra’s algorithm from all vertices of takes time .
Setting gives a final runtime of .
4 Deterministic Small Clusters
A random hitting set of size results in an expected average cluster size of . A deterministic greedy hitting set of size results in an on the size of every ball, and furthermore the average cluster size is small as a result:
However, sometimes we want the size of all clusters to be bounded by . Theorem 3.1 from [39] gave a Las Vegas algorithm for doing so that worked in expected time. Here, we present a deterministic algorithm that works in the same running time.
Lemma 16.
There exists a deterministic algorithm running in time that, when given an matrix consisting of the closest vertices to every node (in a directed or undirected graph), constructs a set of size such that all clusters and balls with respect to are of size at most .
Lemma 17 (Definition 2, Theorem 3 from [36]).
Let be an matrix whose elements are taken from a finite set of size , let be a set, and let be a penalty. Let be the index of the first element of , the -th row of , that belongs to , or , if no element of belongs to . Let be the hitting sum of with respect to .
Then, for every there is an time algorithm which finds a set for which .
Proof of Lemma 16..
The idea is that early hitting sets satisfy the same property that random sets do in the proof of Theorem 3.1 from [39].
Algorithm.
Construct a greedy hitting set (Lemma 9) of size that hits every row of this matrix. Initialize to be this greedy hitting set.
For , we repeat the following:
Compute the balls for every vertex by iterating through each row of and finding the first element in each row which is in , and compute the clusters as the inverse of the balls. Let , i.e. all clusters that are still “too big”. Now, we construct a new matrix , where for each row in , consider only the elements before the first occurrence of that are also members of . Pad all rows of with a dummy element to make them the same length.
In Lemma 17, plug in .
Lemma 17 returns a set . If the dummy element is not included in , we add it in. We set .
Correctness.
Consider the set returned by Lemma 17 after iteration , and the set after is merged in.
Lemma 17 guarantees . Because and all terms are non-negative, we have and . The first inequality yields . From the second inequality, we have .
For a row corresponding to vertex , the set of elements that occur before the first hit (which is the entire row, if no hit occurs), is precisely , and so .
We have . Recall that are the clusters still satisfying at the end of the th iteration. So, we have
, so in iterations, becomes the empty set, at which point all clusters satisfy .
We add at most elements into at every iteration, so the total number of added elements is .
Runtime.
In each iteration, the size of the matrix is bounded by . Lemma 17 constructs the hitting set in linear time in the size of the matrix. The greedy hitting set finds an initial set satisfying for every , so computing all balls and clusters takes time .
There are total iterations, for an overall time complexity of .
Finally, we prove Theorem 2.
Proof of Theorem 2..
It suffices to prove the claim for a weighted, directed graph. First, we use Lemma 8 to compute for the set and in time. Then, we apply Lemma 16 to compute a set of size such that in time.
Similarly, we compute a set of size such that in the same running time.
Finally, we set . Note that balls and clusters are nonincreasing as we add elements to , so satisfies and .
5 New Diameter Approximation Algorithms
5.1 Simplified -Diameter Approximation
We begin by constructing a simple -diameter approximation algorithm with no additive error. Our algorithm runs in time , improving by a log factor upon the runtime of the -approximation algorithm of Chechik et al. [15] with a vastly simpler algorithm. We derive this algorithm from queries to an adaptation of a distance oracle data structure [34] using the classic balls and clusters approach, together with the observation (e.g. [9]) that iterating over all the neighbors of a vertex’s ball can be done efficiently, to avoid the original additive error.
Theorem 18.
Given a weighted, directed graph with diameter , one can compute in time an estimate satisfying .
Recall the diameter approximation algorithm of Roditty and Vassilevska W. [37]. Take a set of size such that every has . Run Dijkstra’s algorithm to and from every vertex in and let be the vertex maximizing . Finally, run Dijkstra’s from and into every vertex in and return the largest distance found. By setting the algorithm achieves a runtime of .
The approximation guarantee comes from the following argument. Consider a pair of diameter endpoints . If , then there exists a point with , which gives us our desired approximation. Otherwise, as it maximizes this distance, meaning contains all points of distance from . If has distance greater than to we are done, otherwise pick a vertex on the shortest path between and that is within distance from - meaning it is contained in - and to - meaning it has distance from . Thus, running Dijsktra’s from all vertices in runs a search out of this vertex and thus guarantees finding a large enough distance. However, such a vertex does not necessarily exist, as on the shortest path between there could be an edge such that while . This causes the algorithm to incur an additive error proportional to the weight of the edge , which could be arbitrarily large.
To address this additive error, Chechik et al. [15] perform a binary search to have an approximate value of the diameter and introduce various new tools in a relatively involved algorithm running in time.
We instead propose a simple algorithm, hinging on the observation that for any pair of vertices that have , if the distance between them is smaller than our target of , then there exists an edge connecting their -balls to each other. We adapt the -distance oracle of Pătraşcu and Roditty [34] to compute the distances between such pairs of points.
Proof of Theorem 18..
We are now ready to formally state our algorithm. See Algorithm 2 for the full pseudo-code.
Using Theorem 2, construct a set of size , using a parameter to be set later, such that all ingoing and outgoing -balls and clusters are of size . Compute for every and run Dijsktra’s algorithm to and from all vertices in .
Next, we compute the distances obtained from paths of the form where and . Denote by the length of the shortest path of this form from to and set if no such path exists, note that in general . For every vertex , we compute all by scanning . For each , each and each we compute . In fact, this is an adaptation to the preprocessing step of the distance oracle of Pătraşcu and Roditty [34], which computes the distances between pairs of points whose -balls intersect in the undirected setting. We can think of this step as the preprocessing of an approximate distance oracle where we later obtain the values by querying the oracle.
Now, for every vertex compute the largest value for a vertex such that . Denote this value by . Similarly, define to be the largest value for a vertex such that . We choose the vertex that maximizes the expression and the vertex that maximizes the expression . We claim that running Dijkstra’s from and to will result in the desired approximation.
Correctness.
Clearly the value returned by the algorithm satisfies , as it is a distance in the graph. We are left to show that .
Fix a pair of diameter endpoints . If , then there exists a point such that and so by the triangle inequality . Thus, the algorithm will have found a sufficiently large distance in line 4. Similarly, if we are done, so we can assume that .
W.l.o.g we can assume , as the reverse case is symmetric. Thus we have that . Since , we conclude that line 12 selects a such that,
Therefore, and , meaning there exists a vertex with such that . We claim that and so running Dijkstra’s from will obtain the desired approximation.
Indeed, if then there exists an edge on the shortest path between and , such that and . Since we have that and . Therefore the path would have been considered in the computation of and we would have , contradiction. We conclude that and the largest distance found from running Dijkstra’s out of obtains the desired approximation.
Runtime.
Computing the set , as well as all balls and the distances within them, takes time. Running Dijsktra’s to and from every vertex in takes assuming . If this is not the case and we can compute a -approximation in time [15].
Computing the values takes time:
The values can be computed at the same time as the values by sorting the vertices in order of distance to/from ahead of time and only considering the values computed. If not all relevant vertices have a value or computed, we assign the value of . Finally, lines 12, 13 and 14 run in near linear time.
The total runtime of the algorithm therefore comes out to . Setting we get a runtime of .
5.2 New -Diameter Approximation
In the next section we provide the first diameter approximation algorithm with multiplicative error not of the form . Our algorithm runs in time and obtains a multiplicative error of . In the worst case, the algorithm has an additive error of . This algorithm is faster than the current best -approximation algorithms (with additive errors) in the regime where .
The algorithm uses the structure of Akav and Roditty’s -distance oracle [6], together with the balls and clusters techniques of classic diameter approximation algorithms. As we cannot afford to preprocess the entire -approximate distance oracle, we construct a partial distance oracle treating only pairs of points with one endpoint in a particular set. While the original work is randomized, we use a deterministic hitting set construction while building the distance oracle to achieve a deterministic diameter approximation algorithm.
Theorem 19.
Given an unweighted, undirected graph with diameter , one can compute in time an estimate satisfying for .
The above algorithm gives us a value such that , i.e. a -approximation to the diameter. If the diameter of the graph is large enough, , we have and obtain a approximation. In the worst case we have , as or can be checked in linear time and if a single BFS finds a distance of . In this case we get and obtain a -approximation.
The idea of our algorithm is as follows. We construct sets , of size and respectively. We can afford to run BFS from all the points in and from a ball of some vertex in time . Using the previous ideas for diameter approximations, this gives us the desired approximation if a diameter endpoint is within distance of or further than away from .
For the remaining case, we show that we have a pair of points and such that both and are large. We now construct a restricted, deterministic version of Akav and Roditty’s -approximate distance oracle to handle such pairs. The idea of this distance oracle is to construct a spanner that guarantees an additive 2 approximation to paths that are fully contained within a single -ball, and thus a +4 approximations to distances between points whose -balls intersect. We now compute all distances out of using the edges of the spanner , this guarantees that the distance obtained, is a good approximation for whenever the balls of and intersect. If they don’t intersect, we can approximate the distance between and with . The distance oracle returns the minimum of these two estimates, to guarantee a lower bound to the true distance between and . We show for the pair of points and mentioned above that this estimate provides the desired approximation.
The construction of the spanner is also randomized in the original work of [6]. The idea of the spanner is to take a hitting set of size that hits the neighborhood of all vertices of degree . We then compute for every and add a shortest path tree spanning to . We complete by adding all edges adjacent to vertices of degree .
We can derandomize this construction by carefully constructing the sets in a particular order. We first construct as a deterministic hitting set to all neighborhoods of vertices of degree . We then compute the -nearest neighbors of each vertex in and construct to be a hitting set for these neighborhoods, to guarantee that all vertices in have small -balls. Finally, for we can afford to use Theorem 2 and construct a set such that all vertices have small -balls.
Proof of Theorem 19..
We can now formally state our algorithm. For full pseudo-code, see Algorithm 3.
Let be parameters to be set later. Using Lemma 9, construct a set of size in time that hits the neighborhood of every vertex of degree . For every compute to be the closest nodes to . Now, again using Lemma 9, construct a hitting set of size in time to hit for every . Note that in this case, for every we have that . Using Theorem 2, construct a set of size in time such that all vertices have .
Following the approach of previous diameter approximation algorithms, begin by running BFS from all vertices in and from the set . Let be the furthest point from and run BFS from every point in .
Fix a pair of diameter endpoints . If , then there exists a point such that and so and running BFS from achieves the desired approximation. Similarly, if we are done.
Continuing along the analysis of previous diameter approximations, if , then . If , then there exists a vertex on the shortest path between and such that and . Therefore and , thus running BFS from all points in obtains the desired approximation.
We are left to handle the case when and . In this case, there exists a vertex such that , and so . Furthermore, since , by the triangle inequality we know that .
To handle this final case we construct a restricted, deterministic version of Akav and Roditty’s -approximate distance oracle to compute an approximation for distances from . We will simply compute an estimate to these distances, but we can think of this step as constructing a distance oracle and querying for every .
Construct the following spanner . Initialize the edges of to contain all edges adjacent to vertices of degree . For every , add a spanning tree of rooted at to . As each -ball of a vertex in is of size this results in having edges. Run BFS from every in the spanner to compute for every . Using a series of claims we will now show that the following distance approximation is a lower bound to the true distance between a pair of points.
Lemma 20.
We prove this lemma by considering two cases. Note that we only use for analysis and don’t have to compute these sets at any point of the algorithm.
Claim 21.
If no shortest path between contains five vertices in then .
Proof.
Consider a shortest path between . Label the vertices . Let be the furthest vertex on the path from that is still in and let be the furthest vertex from that is still in . Then since we cannot have five vertices on the path in we have . Since we know and similarly .
Therefore,
Claim 22.
If a shortest path between contains five vertices in then .
Proof.
Let be a shortest path between such that . Consider the path between and . If all vertices on this path are of degree then the path is contained in and .
Otherwise, let be the first vertex of degree on the path from to and let be a neighbor of . We claim that . Indeed, by the triangle inequality, . Since and we have that . On the other hand, , and so .
Therefore, contains all edges on the path as they are adjacent to vertices of degree . contains the edge as it is part of the spanning tree of . Finally, contains a path of length between and since . We conclude that,
Similarly, we can show that and so we can conclude that:
Therefore, the estimate gives us a lower bound to . Now consider for the vertex and the diameter endpoint discussed above. Since ,
Furthermore, since ,
Therefore, . So returning the largest distance estimate computed will obtain the desired approximation.
Correctness.
By Lemma 20, all values computed are smaller than true distances in the graph. Therefore the value returned is bounded above by a true distance and so .
Runtime.
Using Lemma 9 to construct and takes time, which will be dominated by for the we set. Constructing using a greedy hitting set takes time.
The spanner contains edges adjacent to low degree vertices. Adding the spanning trees to the spanner adds edges for a total of edges. Therefore, computing the distances from vertices takes .
This gives us a final runtime of
Setting we obtain our desired runtime of .
6 Deterministic -Radius Approximation and -All Nodes Eccentricity Approximation
In this section we show that the algorithm introduced in the proof of Theorem 11 can also approximate the radius and all eccentricities of a given graph.
While there is an expected time -approximation algorithm for all eccentricities [17, 8], it is not known how to derandomize these algorithms. Thus, the deterministic algorithm below presents the best known deterministic approximation algorithms for all nodes eccentricities.
Consider Algorithm 4, which runs the same graph searches as Algorithm 1 and outputs radius and eccentricities approximations.
We claim that Algorithm 4 gives the following result.
Theorem 23.
Given an undirected graph with edges weight bounded by and an integer , one can compute in deterministic time an estimate satisfying , and estimates for every satisfying .
We showed the runtime of the algorithm in the proof of Theorem 11, so we are left to show that approximation guarantees, which we do in the subsequent Lemma 24 and Lemma 25. We will follow a very similar proof idea, adjusting the parameters for each problem. To adhere to space constraints, we omit the proofs from this version. See the full version for proofs of the following two lemmas.
Lemma 24.
The value outputted by algorithm 4 satisfies .
Lemma 25.
For every , the value outputted by algorithm 4 satisfies .
References
- [1] Amir Abboud, Karl Bringmann, and Nick Fischer. Stronger 3-sum lower bounds for approximate distance oracles via additive combinatorics. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing, STOC 2023, Orlando, FL, USA, June 20-23, 2023, pages 391–404. ACM, 2023. doi:10.1145/3564246.3585240.
- [2] Amir Abboud, Karl Bringmann, Seri Khoury, and Or Zamir. Hardness of approximation in p via short cycle removal: cycle detection, distance oracles, and beyond. In STOC ’22: 54th Annual ACM SIGACT Symposium on Theory of Computing, Rome, Italy, June 20 - 24, 2022, pages 1487–1500. ACM, 2022. doi:10.1145/3519935.3520066.
- [3] Amir Abboud, Mina Dalirrooyfard, Ray Li, and Virginia Vassilevska Williams. On diameter approximation in directed graphs. In Inge Li Gørtz, Martin Farach-Colton, Simon J. Puglisi, and Grzegorz Herman, editors, 31st Annual European Symposium on Algorithms, ESA 2023, September 4-6, 2023, Amsterdam, The Netherlands, volume 274 of LIPIcs, pages 2:1–2:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2023. doi:10.4230/LIPIcs.ESA.2023.2.
- [4] Amir Abboud, Virginia Vassilevska Williams, and Joshua Wang. Approximation and fixed parameter subquadratic algorithms for radius and diameter in sparse graphs. In Proceedings of the Twenty-Seventh Annual ACM-SIAM Symposium on Discrete Algorithms, SODA ’16, pages 377–391, USA, 2016. Society for Industrial and Applied Mathematics. doi:10.1137/1.9781611974331.CH28.
- [5] 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. doi:10.1137/S0097539796303421.
- [6] Maor Akav and Liam Roditty. An almost 2-approximation for all-pairs of shortest paths in subquadratic time. In Proceedings of the 2020 ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 1–11, 2020. doi:10.1137/1.9781611975994.1.
- [7] Josh Alman, Ran Duan, Virginia Vassilevska Williams, Yinzhan Xu, Zixuan Xu, and Renfei Zhou. More asymmetry yields faster matrix multiplication. In 36th ACM-SIAM Symposium on Discrete Algorithms (SODA 2025), pages 2005–2039. SIAM, 2025. arXiv:2404.16349.
- [8] Arturs Backurs, Liam Roditty, Gilad Segal, Virginia Vassilevska Williams, and Nicole Wein. Towards tight approximation bounds for graph diameter and eccentricities. In Proceedings of the 50th Annual ACM SIGACT Symposium on Theory of Computing, pages 267–280, 2018. doi:10.1145/3188745.3188950.
- [9] 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. doi:10.1137/080737174.
- [10] Aaron Berger, Jenny Kaufmann, and Virginia Vassilevska Williams. Approximating Min-Diameter: Standard and Bichromatic. In 31st Annual European Symposium on Algorithms (ESA 2023), volume 274 of Leibniz International Proceedings in Informatics (LIPIcs), pages 17:1–17:14, 2023. doi:10.4230/LIPIcs.ESA.2023.17.
- [11] Édouard Bonnet. Inapproximability of Diameter in Super-Linear Time: Beyond the 5/3 Ratio. In Markus Bläser and Benjamin Monmege, editors, 38th International Symposium on Theoretical Aspects of Computer Science (STACS 2021), volume 187 of Leibniz International Proceedings in Informatics (LIPIcs), pages 17:1–17:13, Dagstuhl, Germany, 2021. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.STACS.2021.17.
- [12] Massimo Cairo, Roberto Grossi, and Romeo Rizzi. New bounds for approximating extremal distances in undirected graphs. In Proceedings of the Twenty-seventh Annual ACM-SIAM Symposium on Discrete Algorithms, pages 363–376. SIAM, 2016. doi:10.1137/1.9781611974331.CH27.
- [13] Chris Calabro, Russell Impagliazzo, and Ramamohan Paturi. On the exact complexity of evaluating quantified k-cnf. In Venkatesh Raman and Saket Saurabh, editors, Parameterized and Exact Computation - 5th International Symposium, IPEC 2010, Chennai, India, December 13-15, 2010. Proceedings, volume 6478 of Lecture Notes in Computer Science, pages 50–59. Springer, 2010. doi:10.1007/978-3-642-17493-3_7.
- [14] Shiri Chechik. Approximate distance oracles with constant query time. In Proceedings of the forty-sixth annual ACM symposium on Theory of computing, pages 654–663, 2014. doi:10.1145/2591796.2591801.
- [15] Shiri Chechik, Daniel H. Larkin, Liam Roditty, Grant Schoenebeck, Robert E. Tarjan, and Virginia Vassilevska Williams. Better approximation algorithms for the graph diameter. In Proceedings of the Twenty-Fifth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA ’14, pages 1041–1052, USA, 2014. Society for Industrial and Applied Mathematics.
- [16] Shiri Chechik and Tianyi Zhang. Constant approximation of min-distances in near-linear time. In 2022 IEEE 63rd Annual Symposium on Foundations of Computer Science (FOCS), pages 896–906. IEEE, 2022. doi:10.1109/FOCS54457.2022.00089.
- [17] Keerti Choudhary and Omer Gold. Extremal distances in directed graphs: Tight spanners and near-optimal approximation algorithms. In Proceedings of the Fourteenth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 495–514. SIAM, 2020. doi:10.1137/1.9781611975994.30.
- [18] Edith Cohen and Uri Zwick. All-pairs small-stretch paths. Journal of Algorithms, 38(2):335–353, 2001. Announced at SODA 1997. doi:10.1006/jagm.2000.1117.
- [19] Mina Dalirrooyfard and Jenny Kaufmann. Approximation Algorithms for Min-Distance Problems in DAGs. In 48th International Colloquium on Automata, Languages, and Programming (ICALP 2021), volume 198 of Leibniz International Proceedings in Informatics (LIPIcs), pages 60:1–60:17, 2021. doi:10.4230/LIPIcs.ICALP.2021.60.
- [20] Mina Dalirrooyfard, Ray Li, and Virginia Vassilevska Williams. Hardness of approximate diameter: Now for undirected graphs. J. ACM, 72(1), 2025. doi:10.1145/3704631.
- [21] Mina Dalirrooyfard, Virginia Vassilevska Williams, Nikhil Vyas, and Nicole Wein. Tight approximation algorithms for bichromatic graph diameter and related problems. In Christel Baier, Ioannis Chatzigiannakis, Paola Flocchini, and Stefano Leonardi, editors, 46th International Colloquium on Automata, Languages, and Programming, ICALP 2019, July 9-12, 2019, Patras, Greece, volume 132 of LIPIcs, pages 47:1–47:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2019. doi:10.4230/LIPIcs.ICALP.2019.47.
- [22] Mina Dalirrooyfard, Virginia Vassilevska Williams, Nikhil Vyas, Nicole Wein, Yinzhan Xu, and Yuancheng Yu. Approximation Algorithms for Min-Distance Problems. In 46th International Colloquium on Automata, Languages, and Programming (ICALP 2019), volume 132 of Leibniz International Proceedings in Informatics (LIPIcs), pages 46:1–46:14, 2019. doi:10.4230/LIPIcs.ICALP.2019.46.
- [23] Mina Dalirrooyfard and Nicole Wein. Tight conditional lower bounds for approximating diameter in directed graphs. In Proceedings of the 53rd Annual ACM SIGACT Symposium on Theory of Computing, STOC 2021, pages 1697–1710, 2021. doi:10.1145/3406325.3451130.
- [24] Mingyang Deng, Yael Kirkpatrick, Victor Rong, Virginia Vassilevska Williams, and Ziqian Zhong. New additive approximations for shortest paths and cycles. In 49th International Colloquium on Automata, Languages, and Programming (ICALP 2022), pages 50:1–50:10, 2022. doi:10.4230/LIPIcs.ICALP.2022.50.
- [25] Dorit Dor, Shay Halperin, and Uri Zwick. All-pairs almost shortest paths. SIAM Journal on Computing, 29(5):1740–1759, 2000. doi:10.1137/S0097539797327908.
- [26] 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. SIAM, 2024. doi:10.1137/1.9781611977912.169.
- [27] Anita Dürr. Improved bounds for rectangular monotone min-plus product and applications. Information Processing Letters, page 106358, 2023. doi:10.1016/J.IPL.2023.106358.
- [28] Russell Impagliazzo and Ramamohan Paturi. On the complexity of k-sat. Journal of Computer and System Sciences, 62(2):367–375, 2001. doi:10.1006/jcss.2000.1727.
- [29] Ce Jin and Yinzhan Xu. Removing additive structure in 3sum-based reductions. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing, STOC 2023, Orlando, FL, USA, June 20-23, 2023, pages 405–418. ACM, 2023. doi:10.1145/3564246.3585157.
- [30] Telikepalli Kavitha. Faster algorithms for all-pairs small stretch distances in weighted graphs. Algorithmica, 63(1-2):224–245, 2012. Announced at FSTTCS 2007. doi:10.1007/s00453-011-9529-y.
- [31] Mathias Bæk Tejs Knudsen. Additive spanners and distance oracles in quadratic time, 2017. arXiv:1704.04473.
- [32] Ray Li. Settling seth vs. approximate sparse directed unweighted diameter (up to (nu)nseth). In Proceedings of the 53rd Annual ACM SIGACT Symposium on Theory of Computing, STOC 2021, pages 1684–1696, New York, NY, USA, 2021. Association for Computing Machinery. doi:10.1145/3406325.3451045.
- [33] Mihai Patrascu, Liam Roditty, and Mikkel Thorup. A new infinity of distance oracles for sparse graphs. In 2012 IEEE 53rd Annual Symposium on Foundations of Computer Science, pages 738–747. IEEE, 2012. doi:10.1109/FOCS.2012.44.
- [34] Mihai Pǎtraşcu and Liam Roditty. Distance oracles beyond the thorup–zwick bound. SIAM Journal on Computing, 43(1):300–311, 2014. doi:10.1137/11084128X.
- [35] Liam Roditty. New algorithms for all pairs approximate shortest paths. In Barna Saha and Rocco A. Servedio, editors, Proceedings of the 55th Annual ACM Symposium on Theory of Computing, STOC 2023, Orlando, FL, USA, June 20-23, 2023, pages 309–320. ACM, 2023. doi:10.1145/3564246.3585197.
- [36] Liam Roditty, Mikkel Thorup, and Uri Zwick. Deterministic constructions of approximate distance oracles and spanners. In Automata, Languages and Programming, 32nd International Colloquium, ICALP 2005, Lisbon, Portugal, July 11-15, 2005, Proceedings, volume 3580 of Lecture Notes in Computer Science, pages 261–272. Springer, 2005. doi:10.1007/11523468_22.
- [37] Liam Roditty and Virginia Vassilevska Williams. Fast approximation algorithms for the diameter and radius of sparse graphs. In Proceedings of the Forty-Fifth Annual ACM Symposium on Theory of Computing, STOC ’13, pages 515–524, New York, NY, USA, 2013. Association for Computing Machinery. doi:10.1145/2488608.2488673.
- [38] 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. SIAM, 2024. doi:10.1137/1.9781611977912.170.
- [39] Mikkel Thorup and Uri Zwick. Compact routing schemes. In Proceedings of the Thirteenth annual ACM symposium on Parallel algorithms and architectures, pages 1–10, 2001. doi:10.1145/378580.378581.
- [40] Mikkel Thorup and Uri Zwick. Approximate distance oracles. J. ACM, 52(1):1–24, January 2005. doi:10.1145/1044731.1044732.
- [41] R. Ryan Williams. Faster all-pairs shortest paths via circuit complexity. SIAM J. Comput., 47(5):1965–1985, 2018. doi:10.1137/15M1024524.
- [42] Christian Wulff-Nilsen. Approximate distance oracles with improved query time. In Proceedings of the twenty-fourth annual ACM-SIAM symposium on Discrete algorithms, pages 539–549. SIAM, 2013. doi:10.1137/1.9781611973105.39.
- [43] Uri Zwick. All pairs shortest paths using bridging sets and rectangular matrix multiplication. J. ACM, 49(3):289–317, 2002. doi:10.1145/567112.567114.
