A Simple Dynamic Spanner via APSP
Abstract
We give a simple algorithm for maintaining a -approximate spanner of a graph with vertices as receives edge updates by reduction to the dynamic All-Pairs Shortest Paths (APSP) problem. Given an initially empty graph , our algorithm processes insertions and deletions in total time and maintains an initially empty spanner with total recourse . When the number of insertions is much larger than the number of deletions, this notably yields recourse sub-linear in the total number of updates.
Our simple algorithm can be extended to maintain a -approximate spanner with edges throughout a sequence of insertions and deletions with amortized update time and total recourse via batching.
Keywords and phrases:
Dynamic graph algorithms, Spanner, Dynamic Greedy SpannerCategory:
Track A: Algorithms, Complexity and GamesFunding:
Rasmus Kyng: The research leading to these results has received funding from grant no. 200021 204787 and from the starting grant “A New Paradigm for Flow and Cut Algorithms” (no. TMSGI2_218022) of the Swiss National Science Foundation.Copyright and License:
![[Uncaptioned image]](x1.png)
2012 ACM Subject Classification:
Theory of computation Dynamic graph algorithms ; Theory of computation Sparsification and spannersAcknowledgements:
The authors are very grateful for feedback from Maximilian Probst Gutenberg and Pratyai Mazumder on a draft of this article that improved the presentation.Editors:
Keren Censor-Hillel, Fabrizio Grandoni, Joël Ouaknine, and Gabriele PuppisSeries and Publisher:

1 Introduction
Given a graph , a -approximate spanner is a subgraph of with the same vertex set such that for every pair of vertices .111 is called the stretch of . Typically, the spanner has much fewer edges than and can therefore be used as a sparse proxy for computing approximate distances in downstream applications. Althöfer, Das, Dobkin, Joseph and Soares developed the now-classical greedy spanner [1].
Given an integer , their algorithm incrementally constructs a -approximate spanner of as follows.
-
1)
Initialize .
-
2)
Consider the edges in arbitrary order. If , add to .
When this process finishes, every edge on the shortest path between two arbitrary vertices in can be replaced by a detour of length at most in . The claimed approximation directly follows.
Crucially, they show that the graph is also sparse. This follows from the folklore observation that high-girth graphs are sparse. The girth of a graph is the length of the shortest cycle. By construction, the girth of is , which implies total edge count is bounded by . Whenever grows with , this leads to an almost-linearly sized spanner.
Observation 1 (Folklore).
Every graph with girth contains at most edges.
Proof.
Repeatedly remove vertices of degree at most from . This process removes at most edges. Assume for the sake of a contradiction that there is some remaining graph after this process terminates. Fix an arbitrary remaining vertex , and consider the breath-first search tree to depth from . Since the girth of is at least , no two vertices at depth in share an edge in . Thus, the number of vertices in is at least which is a contradiction.
Despite the simplicity of this framework, previous deterministic dynamic algorithms for maintaining a spanner as undergoes updates were based on expander decompositions [7, 5].
However, In [4] the authors observed that the greedy spanner construction can be used to maintain a spanner as receives edge deletions with low amortized recourse. As part of their almost-linear time incremental min-cost flow algorithm, [6] presented a computationally efficient algorithm for maintaining a spanner of a fully-dynamic graph based on the greedy spanner.222They crucially exploit that the recourse is sub-linear in the number of insertions. Expander decomposition based algorithms seem less suitable for achieving such a result. Their algorithm is complicated by the fact that they need to process vertex splits in addition to edge updates and the total number of decremental updates is limited by the number of vertices.
1.1 A simple dynamic spanner for graphs with few deletions
We present a simplified algorithm for maintaining a spanner of an edge-dynamic graph by reduction to an All-Pairs Shortest Paths (APSP) oracle. The underlying APSP oracle is a dynamic algorithm providing query access to approximate pairwise distances in a dynamic graph [9, 12, 11, 13].
Theorem 2.
Given an initially empty edge-dynamic graph on vertices receiving edge insertions and up to edge deletions where , there is an algorithm maintaining a -approximate spanner with total update time and total recourse .
We note in particular that the total recourse is almost-optimal and only depends on the number of vertices and deletions, and is therefore completely independent of the number of insertions.
Our simple algorithm yielding Theorem 2 is presented in Section 4. It can use any path-reporting approximate APSP data structure and only adds an factor overhead in runtime and approximation. We refer the reader to Definition 5 and Theorem 12 for a more fine grained analysis of the dependency on the underlying APSP data structure.
Remark 3.
Theorem 2 can be extended to graphs with polynomially bounded edge lengths via standard length bucketing. The number of edges in the final spanner increases by a logarithmic factor.
1.2 More deletions and lower stretch dynamic spanners
Batching techniques allow us to extend our spanner to handle an arbitrary number of deletions, where the recourse becomes almost-linear in the number of deletions and vertices.
An originally independent work [8] recently introduced the idea of obtaining a dynamic spanner with stretch .333The first version of this article on arXiv precedes the announcement of [8], but their article prompted us to add Theorem 4 and Section 5. They remark that prior to their work, no algorithm with update time , edges and stretch existed. This motivated us to extend our spanner to handle arbitrary non-constant stretch as in Theorem 18. They heavily use ideas from [11] directly, which we completely black-box. We remark that our algorithm loses large sub-polynomial factors in update time and density compared to theirs.
Theorem 4.
Given an edge-dynamic graph with vertices receiving insertions and deletions, and a parameter , there is an algorithm maintaining a -approximate spanner containing at most edges with total recourse and amortized update time .
Our algorithm yielding Theorem 4 is presented in Section 5. It depends on the APSP data structure of [11], which can get arbitrarily good approximation by trading it off for update time. We point out that the recourse achieved by our algorithm is again almost-optimal, since scaling linearly in the number of deletions is unavoidable.
1.3 Prior Work
In [2], the authors present a randomized dynamic spanner with poly-logarithmic stretch and amortized update time against an oblivious adversary.444Oblivious adversaries generate the sequence of updates at the start, i.e. independently from the random output of the algorithm. Adaptive adversaries can use the previous output to fool a randomized algorithm. Then [10] significantly reduced the poly-logarithmic overhead in both size and update time. In [3], the authors gave the first non-trivial algorithm for maintaining a dynamic spanner against an adaptive adversary. They maintain a spanner of near linear size with poly-logarithmic amortized update time and stretch. Deterministic algorithms for maintaining spanners of dynamic graphs with bounded degree that additionally undergo vertex splits were developed in the context of algorithms for minimum cost flow [7, 5, 6]. These have sub-polynomial overhead.
2 Preliminaries
2.1 Static and Dynamic Graphs
We let denote unweighted and undirected graphs with vertex set and edge set . When we want to refer to the vertex/edge set of some graph , we sometimes use and respectively.
We refer to as the density of a graph, and say a graph is sparse whenever its density is .
For a graph and a pair of vertices we let denote the length of a shortest -path in . We call a graph edge-dynamic if it receives arbitrary updates to (i.e. edge insertions and deletions). We refer to the total number of such edge updates a graph receives as the recourse.
2.2 Edge Embeddings
Given two graph and on the same vertex set such that , we let be a function that maps edges in to paths in . Given an embedding , we define the edge congestion for .
3 Dynamic All-Pairs Shortest Paths
We first define approximate All-Pairs Shortest Paths (APSP) data structures for edge-dynamic graphs.
Definition 5 (APSP).
For an initially empty edge-dynamic graph a -approximate -update -query APSP data structure supports the following operations.
-
/ : Add/Remove edge from/to in (amortized) time .
-
: Returns a distance estimate such that
in (amortized) time .
-
: Returns a simple -path in of length in time .
We refer the reader to [9, 12, 11, 13] for recent results on path-reporting dynamic APSP. The parameters and should currently be thought of as sub-polynomial factors in the number of vertices of type for some constant .
In [13] the authors present the shortest APSP algorithm yet by simplifying the algorithm of [12] at the expense of a larger sub-polynomial overhead in runtime, i.e. for some . Their algorithm internally bootstraps a more complicated version of the spanner presented in this article that is tailored to their application.
The algorithm of [11] can obtain a better approximation at the cost of large sub-polynomial update times .
4 A Dynamic Greedy Spanner
4.1 A Simple Low-Recourse Algorithm
We first present a very simple dynamic variant of the greedy spanner that merely limits the number of changes to , i.e. its recourse. Then we describe the necessary changes for obtaining an efficient version using a dynamic APSP datastructure.
Let be an initially empty graph on vertices. We maintain a -spanner as follows.
-
When an edge is inserted to , we check if . If so, we add it to .
-
When an edge is deleted from , we remove it from if it is present and re-insert all edges in using the procedure described above. If is not in , we do not need to update our spanner.
This algorithm still maintains that the girth of is at least , and therefore the graph contains at most edges at any point. Edges only leave the spanner when they are deleted. If at most edges get deleted throughout, a total recourse bound of follows directly since the total recourse is bounded by .
4.2 A Simple Efficient Algorithm
To turn the above framework into an efficient algorithm, we maintain an embedding that maps each edge in to a short path in and thus certifies that such a path still exists. We then only have to re-insert all edges whose embedding paths use the deleted edge. To bound the number of re-insertions, we carefully manage the edge congestion of . Finally, we use an APSP data structure (See Definition 5) to obtain distances and paths. In the following, we assume there are at most insertions, deletions and that .
Our algorithm internally maintains two graphs: The current spanner and a not yet congested sub-graph . We maintain that the edge congestion is strictly less than for every edge in , and maintain access to distances and paths in via a -approximate -update -query APSP data structure .
-
When an edge is inserted, we check if returns distance at most between the endpoints. If this is the case, we query it for a witness path and store as the embedding path of . Then we check if any of the edges on the path now have embedding paths using them, and if so we remove them from . Otherwise, we add the edge to and .
-
When an edge is deleted, we remove it from and and re-insert all edges that now have a broken embedding path using the procedure above.
Choosing the threshold allows us to tolerate up to deletions which yield additional calls to the insertion procedure. See Algorithm 1 for detailed pseudocode.
4.3 Analysis
We first show that is a -approximate spanner.
Lemma 6.
The graph maintained by (Algorithm 1) is a -approximate spanner throughout.
Proof.
When an edge is inserted, it afterwards has a valid embedding path of length at most by the description of . Therefore the edge has a valid embedding path at this point. However, if any edge on this path is deleted, the edge is re-inserted by the description of . This establishes the claim.
We then prove that the total number of times the routine is called is bounded by .
Claim 7.
For all , throughout.
Proof.
Whenever the edge congestion of an edge in reaches it is removed from and . By the description of such an edge is never used in embedding paths again. Therefore the edge congestion of is bounded by for every edge.
Corollary 8.
A sequence of at most external insertions and deletions causes at most calls to in total.
Proof.
By Claim 7, the edge congestion is at most throughout. Thus, there are at most additional calls to issued by the routine since the algorithm re-inserts every edge with a broken embedding path. The corollary follows.
Given the previous corollary, we are ready bound the total recourse of .
Claim 9.
throughout a sequence of insertions and deletions.
Proof.
We bound the edges in and in separately, starting with the former. These edges were congested by paths when they were removed from . Since the total number of edges ever added is , the total cumulative congestion that all the edges ever experience is at most by the description of . Therefore, the total number of edges in is at most . Finally, by Definition 5 the graph has girth at least , and therefore at most edges by Observation 1.
Corollary 10.
The recourse of is .
Proof.
Follows from Claim 9 since at most edges get removed from .
It remains to bound the total time spent processing updates.
Lemma 11.
The algorithm processes insertions and deletions in total time .
Proof.
There are at most calls to . Each such call causes a distance and possibly a path reporting query to . Whenever a path reporting query is called, the resulting path has length at most . This causes a total runtime of .
Then, by Corollary 10, at most edges get added and therefore also removed from . These cause update calls to . This causes total runtime .
All other operations can be subsumed in the times above.
Our first theorem then follows directly after setting .
Theorem 12 (Simple Spanner to APSP Reduction).
Given a -approximate -update -query APSP data structure (Definition 5), there is an algorithm that maintains a -approximate spanner of an initially empty graph on vertices throughout a sequence up to insertions and deletions in total time . The total recourse of is .
Proof.
Follows from Corollary 10 and Lemma 11 with .
Then, Theorem 2 follows from Theorem 12 in conjunction with any of the APSP data structures of [9, 12, 11]. We point out that the quality of the spanner could be improved to at the expense of a loss of a rather large sub-polynomial factor in update time and recourse using the APSP data structure of [11] (See Theorem 19). In the next section, we exploit their data structure to obtain lower stretch spanners.
5 Lower Stretch & More Deletions
The advantage of the data structure from Theorem 12 is that it has sublinear recourse if the number of insertions is much larger than the number of deletions. On the flip side, processing many deletions is expensive if the input graph is dense. In some applications, spanners are used to further sparsify graphs that are already pretty sparse [7, 5, 12, 13], but in others this may cause significant overhead.
We thus want to modify our spanner to allow for (1) an arbitrary amount of edge deletions instead of as before, and (2) arbitrary stretch instead of as before. We start by noting that replacing the factor in Line 6 of Algorithm 1 with for some arbitrary directly yields the following.
Lemma 13.
Let . Then if we replace the factor in Line 6 of Algorithm 1 by , the following properties hold for a sequence of insertions and deletions:
-
1.
The graph maintained is a spanner throughout.
-
2.
throughout a sequence of insertions and deletions.
-
3.
The recourse of is .
The algorithm runs in total time .
Proof.
The proof of the first item is completely analogous to the proof of Lemma 6. The second item follows from Observation 1 and the bound on the number of congested edges as in Claim 7 applied analogously as in the proof of Claim 9. Finally, the last item follows from the bound on the number of edges and by the fact that edges only leave the spanner when they get deleted.
5.1 Stepwise sparsification for processing more deletions
We now show that we can allow for an arbitrary amount of deletions at the cost of a subpolynomial overhead in both stretch and update time.
Previously, we chose the density reduction parameter , which corresponds to completely sparsifying the graph in one step. To handle more deletions, we choose much smaller, but then recursively compute spanners of spanners until we reach the desired sparsity. We call each such round of sparsification a layer.
Concretely, we let the density reduction be a tunable parameter and assume for some integer number of layers . Reducing the density by for layers will ensure that we reach the desired sparsity via the algorithm outlined below.
5.2 Layered algorithm
We initialize , and recursively apply Algorithm 1 to obtain from for . We let be the desired spanner. We then dynamically maintain this hierarchy throughout a sequence of up to insertions and deletions to . Concretely, we go over the layers in ascending order and at layer feed all the changes caused to to the spanner data structure maintaining . This may lead to updates of , which then get passed to the next layer as long as .
Whenever the graph has experienced some multiple of deletions, we re-initialize layers . We call this a rebuild. The reason rebuilds are required is to maintain sparsity, as otherwise the number of congested edges would grow too much on layers with higher indices due to re-insertions. We stress that the timing of rebuilds only depends on the update sequence to the original graph .
The key insight that enables this algorithm is that edge deletions in always correspond to edge deletions in , i.e. deletions to might cause some extra insertions to , but never more deletions. This is crucial since deletions cause a large amount of recourse, but recourse due to insertions is effectively sparsified.
We first show that the final spanner has the desired sparsity.
Claim 14 (Sparsity).
At any time, .
Proof.
We show the claim by induction on . For , the claim follows directly. Then, for , the claim follows by Lemma 13 and the fact that the layers with indices get re-started after an interval of deletions happened.
We bound the number of rebuilds of layer directly.
Claim 15 (Rebuilds).
After edge insertions and edge deletions, the total number of rebuilds of layer is .
Proof.
The claim directly follows from the description of our algorithm, i.e. a rebuild of layer happens whenever a multiple of deletions happened since the last rebuild.
We then bound the recourse of the graph in a more fine grained manner.
Claim 16.
The recourse of after deletions is bounded by .
Proof.
In between two rebuilds the recourse of is at most . The total number of rebuilds is bounded by . Therefore, the claim follows.
Finally, we prove that the stretch of the final spanner is sufficiently bounded as long as is very small.
Claim 17 (Stretch).
The total stretch of the spanner computed at layer with respect to is at most .
Proof.
We conclude with the main theorem of this section.
Theorem 18.
Given a -approximate -update -query APSP data structure (Definition 5) and parameters , there is an algorithm that maintains a -approximate spanner of an initially empty graph on vertices throughout an arbitrary sequence of edge insertions and deletions such that with amortized update time .
Proof.
Sparsity and stretch follow from Claim 14 and Claim 17, respectively. It remains to show the statement about run-time. Suppose we received edge-insertions and edge-deletions. Each layer handles up to insertions and deletions before being restarted, which takes time by Lemma 13. The total number of restarts of layer is , so that the total amount of time spent for layer is . Summing the costs over all layers yields the statement.
The following theorem from [11] allows us to instantiate our parameters in a suitable way. Since our approximation factor is larger than , we rely on the ability to choose a very small approximation factor in their APSP algorithm. Then, we choose to be a very large sub-polynomial factor to obtain very few layers .
Theorem 19 (Theorem in [11]).
For some small constant , given a parameter , there is a -approximate, -update and -query APSP data structure.
Theorem 20.
Given parameters , and , there is an algorithm that maintains a -approximate spanner of an initially empty graph on vertices throughout an arbitrary sequence of edge insertions and deletions such that with amortized update time .
Now Theorem 4 follows from the previous theorem by a specific choice of parameters.
Proof of Theorem 4.
We choose , and . Note that then .
So for this choice of parameters, the stretch is
The sparsity is
and the amortized update time is
Finally, the desired recourse bound follows from Claim 16.
References
- [1] Ingo Althöfer, Gautam Das, David Dobkin, Deborah Joseph, and José Soares. On sparse spanners of weighted graphs. Discrete & Computational Geometry, 9(1):81–100, 1993. doi:10.1007/BF02189308.
- [2] Surender Baswana, Sumeet Khurana, and Soumojit Sarkar. Fully dynamic randomized algorithms for graph spanners. ACM Trans. Algorithms, 8(4), 2012. doi:10.1145/2344422.2344425.
- [3] Aaron Bernstein, Jan van den Brand, Maximilian Probst Gutenberg, Danupon Nanongkai, Thatchaphol Saranurak, Aaron Sidford, and He Sun. Fully-Dynamic Graph Sparsifiers Against an Adaptive Adversary. In Mikołaj Bojańczyk, Emanuela Merelli, and David P. Woodruff, editors, 49th International Colloquium on Automata, Languages, and Programming (ICALP 2022), volume 229 of Leibniz International Proceedings in Informatics (LIPIcs), pages 20:1–20:20, Dagstuhl, Germany, 2022. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.ICALP.2022.20.
- [4] Sayan Bhattacharya, Thatchaphol Saranurak, and Pattara Sukprasert. Simple Dynamic Spanners with Near-Optimal Recourse Against an Adaptive Adversary. In Shiri Chechik, Gonzalo Navarro, Eva Rotenberg, and Grzegorz Herman, editors, 30th Annual European Symposium on Algorithms (ESA 2022), volume 244 of Leibniz International Proceedings in Informatics (LIPIcs), pages 17:1–17:19, Dagstuhl, Germany, 2022. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.ESA.2022.17.
- [5] J. Brand, L. Chen, R. Kyng, Y. P. Liu, R. Peng, M. Gutenberg, S. Sachdeva, and A. Sidford. A deterministic almost-linear time algorithm for minimum-cost flow. In 2023 IEEE 64th Annual Symposium on Foundations of Computer Science (FOCS), pages 503–514, Los Alamitos, CA, USA, November 2023. IEEE Computer Society. doi:10.1109/FOCS57990.2023.00037.
- [6] Li Chen, Rasmus Kyng, Yang P. Liu, Simon Meierhans, and Maximilian Probst Gutenberg. Almost-linear time algorithms for incremental graphs: Cycle detection, sccs, s-t shortest path, and minimum-cost flow. In Proceedings of the 56th Annual ACM Symposium on Theory of Computing, STOC 2024, pages 1165–1173, New York, NY, USA, 2024. Association for Computing Machinery. doi:10.1145/3618260.3649745.
- [7] Li Chen, Rasmus Kyng, Yang P. Liu, Richard Peng, Maximilian Probst Gutenberg, and Sushant Sachdeva. Maximum flow and minimum-cost flow in almost-linear time. In 2022 IEEE 63rd Annual Symposium on Foundations of Computer Science (FOCS), pages 612–623, 2022. doi:10.1109/FOCS54457.2022.00064.
- [8] Julia Chuzhoy and Merav Parter. Fully dynamic algorithms for graph spanners via low-diameter router decomposition. In Proceedings of the 2025 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 785–823, 2025. doi:10.1137/1.9781611978322.23.
- [9] Julia Chuzhoy and Ruimin Zhang. A new deterministic algorithm for fully dynamic all-pairs shortest paths. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing, STOC 2023, pages 1159–1172, New York, NY, USA, 2023. Association for Computing Machinery. doi:10.1145/3564246.3585196.
- [10] Sebastian Forster and Gramoz Goranci. Dynamic low-stretch trees via dynamic low-diameter decompositions. In Proceedings of the 51st Annual ACM SIGACT Symposium on Theory of Computing, STOC 2019, pages 377–388, New York, NY, USA, 2019. Association for Computing Machinery. doi:10.1145/3313276.3316381.
- [11] Bernhard Haeupler, Yaowei Long, and Thatchaphol Saranurak. Dynamic deterministic constant-approximate distance oracles with worst-case update time, 2024. doi:10.48550/arXiv.2402.18541.
- [12] Rasmus Kyng, Simon Meierhans, and Maximilian Probst Gutenberg. A dynamic shortest paths toolbox: Low-congestion vertex sparsifiers and their applications. In Proceedings of the 56th Annual ACM Symposium on Theory of Computing, STOC 2024, pages 1174–1183, New York, NY, USA, 2024. Association for Computing Machinery. doi:10.1145/3618260.3649767.
- [13] Rasmus Kyng, Simon Meierhans, and Gernot Zöcklein. Bootstrapping dynamic apsp via sparsification, 2024. doi:10.48550/arXiv.2408.11375.