Manuscript Offprint
arXiv:2611.05713Incremental Minimum Spanning Trees on a Napkin
Abstract
In the incremental minimum spanning forest problem, weighted edges arrive one at a time. After each insertion we must report the edge that leaves the minimum spanning forest, and queries ask for the bottleneck distance of two vertices: the smallest possible maximum edge cost on a path between them. Link-cut trees solve both in amortized time. In 2021 we wrote the folklore BottleneckTree, a short competitive-programming structure that stores one parent pointer and one cost per vertex, and conjectured that it also runs in amortized time. We show that this conjecture is false: on a family of inputs, its amortized cost per operation is . We then present a structure with the same state, two arrays and a single loop, and prove that it runs in amortized time per insertion and per query. Unlike the AM-tree of Ding, Gu and Sun, which attains the same bound, it stores no subtree sizes and maintains no balance invariant. For a connected graph with distinct costs, the structure can be viewed as an implicit link-cut tree on the Kruskal reconstruction tree: each rotation corresponds to exactly one preferred-child change, and each skip acts on a stale path-parent pointer. In experiments it is 1.3–2.1 times faster than the folklore BottleneckTree on insertions, up to 480 times faster on its adversarial input, and 6.3–16 times faster than an explicit link-cut tree.
1 Introduction
Maintaining a minimum spanning forest (MSF) while edges arrive one at a time is a basic dynamic graph problem, known as incremental minimum spanning tree. The graph has the vertices and real edge costs, starts without edges, and supports two operations.
AddEdge: insert the edge with cost and return the cost of the edge that leaves the MSF: the cost of the removed edge if the new edge enters the forest, if the new edge does not enter, and if and were in different components (then no edge leaves).
Query: return the bottleneck distance of and , the minimum over all paths of the maximum edge cost on the path ( if no path exists).
The problem is used for connectivity queries on temporal graphs [1, 2]: if each edge costs minus its arrival time, the edges that arrived after time connect and exactly when Query, which answers sliding-window connectivity [3] without deletions. The structure also maintains the MSF of an edge stream in space, and Query is the level at which single-linkage clustering merges and .
How simple can a logarithmic solution be? The classical solution stores the forest in a link-cut tree [4, 5] and takes amortized time per operation, at the price of splay trees, path-parent pointers and reversal bits. Recent work uses a much simpler object: a rooted tree on
| structure | state | amortized time per operation |
|---|---|---|
| link-cut tree [5] | child and parent pointers, reversal bit and path maximum, for every vertex and every forest edge | |
| AM-tree [2] | parent, cost and subtree size per vertex | |
| folklore BottleneckTree [6] | parent and cost per vertex | (Theorem 13) |
| this paper (Fig. 2) | parent and cost per vertex | (Theorem 7) |
Table 1: Structures for incremental MST and bottleneck queries. For the AM-tree we list its lazy variant; the strict variant also stores child pointers and bounds the worst-case query time. The lower bound for the folklore BottleneckTree holds on an explicit family of inputs.
the vertices, with one parent pointer and one cost per vertex, whose path maxima equal those of the MSF. The OEC-forest [1] uses such a tree, but no bound better than per operation is known for it. The AM-tree [2] attains amortized time by also storing subtree sizes and enforcing an anti-monopoly rule: no child may hold more than two thirds of its parent's subtree.
In 2021 we wrote the folklore BottleneckTree [6] for competitive programming. It uses the same kind of tree, stores nothing else, and fits in a few lines of code. Its header states the bound “probably amortized”, which we conjectured when writing it. No proof has been given.
Our results. We show that this conjecture is false: on an explicit family of inputs, the folklore BottleneckTree takes amortized time per operation, and we explain informally why our analysis does not apply to it (Section 6). We then give a structure with exactly the same state that provably runs in amortized time. Table 1 summarizes the comparison.
Like the AM-tree and the folklore BottleneckTree, our structure changes the tree only by two local moves: a rotation, which swaps a vertex with its parent, and a skip, which makes a vertex a child of its grandparent (Section 2). Our structure differs from both mainly in the order in which it applies these moves when it brings a vertex to the root, and unlike the AM-tree it stores no sizes. Bringing a vertex to the root naively, by repeatedly rotating or skipping it, behaves like move-to-root in binary search trees [7] and takes linear time on simple inputs. We add two small repairs, in which the parent first moves one step up itself; they make the cost logarithmic without storing subtree sizes, and in our experiments, dropping either of them makes it linear again (Theorem 9). The analysis uses the potential of the AM-tree.
We also show that, for a connected graph with distinct costs, the structure acts as an implicit link-cut tree on the Kruskal reconstruction tree, the tree of merges performed by Kruskal's algorithm (Section 5). Every rotation is exactly one preferred-child change, which a link-cut tree performs by splaying an auxiliary tree.
In experiments (Section 7), our structure is 1.3–2.1 times faster on insertions than the folklore BottleneckTree, up to 480 times faster on its adversarial input, and 6.3–16 times faster than a link-cut tree. The lazy AM-tree variants are mostly faster than ours, by up to 2 times, when edges arrive in random order; when consecutive edges are close in the graph, ours is competitive, and on a band-shaped graph inserted in this order it is 1.1–1.6 times faster than both.
Outline. Sections 2 to 4 give the moves, the algorithm and its analysis, Section 5 the link-cut-tree view, Section 6 the lower bound, and Section 7 the experiments.
We write for the bottleneck distance of u and w in G. It equals the maximum cost on the u-w path of any MSF of G.
Representation. The structure maintains a rooted tree on . Each non-root vertex stores its parent and the cost of the edge . Initially, every vertex is a child of 0 with the placeholder cost , and the root has the sentinel cost , which exceeds every other cost. This remains true: the operations below exchange costs only between a vertex and its parent, so the cost of the root moves with the root, and the cost update in AddEdge acts on a non-root vertex. We assume that all inserted costs are finite. The edges of need not be edges of . The structure maintains the following invariant, as do the OEC-forest and the AM-tree.
Invariant (I). For all , the maximum cost on the path of equals .
Let be a non-root vertex with parent , and let and , where if is the root. The edge of is an up edge if and a down edge otherwise. We use two moves (Fig. 1), which correspond to the rotate and shortcut cases of the Promote operation of the AM-tree [2].
Rotation of (requires ). Vertex takes the place of : it becomes a child of the parent of with cost (or the root, if was the root), and becomes a child of with cost . No other vertex changes its parent.
Skip of (requires ; then is not the root). Vertex becomes a child of and keeps the cost .

rotation of ():
swaps with its parent

skip of ():
x becomes a child of its grandparent g
Figure 1: The two moves. Each edge is labeled with the cost stored at its lower endpoint. The triangles A, B and C stand for the other children of x, p and g with their subtrees; they keep their parents, and no other vertex changes its parent.
Lemma 1 (cf. [1, 2]). Rotations and skips preserve Invariant (I).
Proof. A tree path that uses a modified edge enters and leaves the set , so it suffices to compare the path maxima between pairs of these vertices. For a rotation, the pairs , , have maxima , , before and , , after; if is the root, only the pair exists and keeps the maximum . For a skip, the maxima are , , before and , , after.
Every edge is an up edge or a down edge, so a non-root vertex can always move one level up: by a rotation if its edge is up, and otherwise by a skip, since a child of the root always has an up edge.
3 The algorithm
Procedure moves x to the root of T. Let and . Each iteration of its loop performs one of four cases.
(A) The edge of x is an up edge: rotate x.
(B) The edges of x and p are down edges: skip p, then skip x.
(C) The edge of is a down edge, the edge of is an up edge, and : rotate , then skip .
(D) The edge of x is a down edge, the edge of p is an up edge, and : skip x.
Thus, at a down edge, first takes one step of its own, provided the step does not raise above (in case (D), does not move), and then skips . Figure 2 gives the complete implementation.
Lemma 2. Every move performed by access is a legal rotation or skip. In cases , p is not the root, and in cases and , g is not the root.
Proof. A child of the root has an up edge, since the root has cost . Hence in cases (B)–(D) the vertex is not the root. In case (B), ; in case (C), ; so is not the root in either case. In case (B), has a down edge and may skip; afterwards is still a child of with and may skip. In case (C), has an up edge and may rotate; afterwards equals the old , so may skip. In case (D), has a down edge.
Each iteration decreases the depth of x, by one in cases (A) and (D) and by two in cases (B) and (C), so terminates with x at the root.
Lemma 3. Let . After and , the root of T is y, x is a child of y, and .
Proof. After , is the root and . During , remains the root until rotates over it: a skip of a child of would need to be at most the child's cost, and by Theorem 2 case (B) or (C) never acts on . When rotates over , becomes the root, becomes its child, and the loop ends. The last claim follows from Invariant (I). const int INF = 1e9; struct BottleneckTree { vector<int> link, cost; // all inserted costs must be < INF BottleneckTree(int n) : link(n, 0), cost(n, INF) { link[0] = -1; cost[0] = INF + 1; } void rot(int x) { int p = link[x], g = link[p]; swap(cost[x], cost[p]); link[x] = g, link[p] = x; } void skip(int x) { link[x] = link[link[x]]; } void access(int x) { for (int p = link[x]; p != -1; p = link[x]) { int g = link[p]; if (cost[x] <= cost[p]) rot(x); // (A) else if (cost[p] > cost[g]) skip(p), skip(x); // (B) else if (cost[g] <= cost[x]) rot(p), skip(x); // (C) else skip(x); // (D) } } int Query(int x, int y) { access(x); access(y); return cost[x]; } int AddEdge(int x, int y, int c) { access(x); access(y); if (cost[x] > c) swap(cost[x], c); return c; } };
Figure 2: The complete data structure. INF represents and INF + 1 the sentinel . The structure keeps the name of the code it replaces (Fig. 4).
Lemma 4. Query returns . AddEdge preserves Invariant (I) and returns the cost of the edge that leaves the MSF.
Proof. The first claim is Theorem 3. Let after the two accesses, and let with cost . For all ,
so depends only on and . Viewed as a weighted graph, satisfies by Invariant (I), and therefore . The only cycle of consists of and the edge of cost . By the cycle property, the MSF of is with the cost of replaced by , which is the tree after the swap. Again by the cycle property, the edge that leaves the MSF of is a most expensive edge of the cycle closed by , whose cost is for any tie-breaking; this is the returned value, and it is if and were disconnected.
4 Analysis
The cost of an access is the number W of loop iterations, each of which takes constant time. For the analysis, let be the number of vertices in the subtree of v in T, and let
Initially , and always. The cost swap in AddEdge changes no subtree, so changes only during accesses.
Lemma 5. Let a be a child of b.
(i) A rotation of a changes by . If , this is at most -1, and we call the rotation heavy.
(ii) A skip of a changes by . If , this is at most -1, and we call the skip heavy.
Proof. A rotation gives the former subtree of and leaves with the other vertices; no other subtree changes. A skip removes the subtree of from that of and changes no other subtree size.
Fix an access, and let be the root path of the accessed vertex when the access begins, with subtree sizes at that time.
Lemma 6 (Untouched ancestors). At the start of every iteration of , the parent of x and all its ancestors have the parent pointers and subtree sizes they had when the access began. In particular, if the parent of x is not the root, the parent and grandparent of x are consecutive vertices of the original root path.
Proof. An iteration modifies only the pointers and subtree sizes of , and . After the iteration, the parent of is the former in cases (A) and (D), and the former parent of in cases (B) and (C); in both cases it was not modified. The set of vertices below each ancestor of the new parent is unchanged. The claim follows by induction.
By Theorem 6, the pair in cases (B) and (C) is a pair of consecutive original path vertices with their original sizes. Since moves above in these cases, different iterations use disjoint pairs.
Theorem 7. For every access,
Proof. Each iteration is charged one unit, except that an iteration of case (D) is charged to the next iteration. The next iteration is of case (A): after the skip, the parent of is the former , and . Hence an iteration of case (A) carries at most two units and every other charged iteration carries one. By Theorem 5(ii), skips of do not increase . We bound the contribution of each case to .
Case (A). A heavy rotation contributes at most . A light rotation increases by a factor greater than 3/2. Only case-(A) rotations change , so there are at most
light rotations. A light rotation increases by at most , the logarithm of the factor by which grows, and these terms sum to at most . Case (A) contributes at most .
Case (B). If the skip of is heavy, the iteration contributes at most . Otherwise for the pair . The pairs are disjoint and the sizes increase along the path, so this happens at most times, and does not increase.
Case (C). If the rotation of is heavy, the iteration contributes at most . Otherwise , which happens at most times, and the increases over disjoint pairs sum to at most . Case (C) contributes at most .
Summing gives , and .
Corollary 8. Any sequence of operations performs at most loop iterations. Hence AddEdge and Query run in amortized time.
Proof. Each operation performs two accesses. Sum Theorem 7 over all 2m accesses, and use and .
Remark 9. Both repairs of are needed. Deleting the lines of cases (B) and (C) from Fig. 2 leaves the naive loop, in which only rotates or skips; this is the promotion of the AM-tree without its size-based rebalancing. In our experiments, two inputs show that each repair is needed on its own. On the star built by AddEdge for , accessing in order costs about two iterations per access with the loop of Fig. 2, but about without case (C). On the path built by AddEdge for , whose costs increase towards vertex 0, the queries Query for cost about four iterations each with the loop of Fig. 2, but about without case (B). Without case (B), the line of case (C) must also test , so that rotates only at an up edge.
5 The structure as an implicit link-cut tree
This section interprets the structure; the analysis of Section 4 does not depend on it. Here, is connected and all inserted costs are distinct. Then contains no placeholder edges, and its costs are distinct as well: for every , the number of edges of cost in a tree is determined by its bottleneck distances, so by Invariant (I) it is the same for as for the MSF. The Kruskal reconstruction tree of a spanning tree, also known as its single-linkage dendrogram or the Cartesian tree of its edges [8], has the vertices as leaves and one internal node per edge, created in increasing order of cost: the node of an edge has the two components joined by the edge as children, and its level is the edge cost. By Invariant (I), the reconstruction tree of equals that of the MSF of . Since rotations and skips preserve all bottleneck distances, accesses do not change .
Definition 10. A non-root vertex owns the internal node of at level . For an internal node , the representative rep is the unique leaf of that owns no node inside . The preferred child of is the child that contains rep.
The representative is well defined. The node created by the edge of contains , so each of the internal nodes of a node with leaves is owned by a distinct leaf of that node, and exactly one leaf owns none of them. As in a link-cut tree, preferred children partition into paths that end at leaves. For a non-root vertex , let be the node it owns. We call stale if it is not rep. Figure 3 shows an example.

Figure 3: A tree with and (left) and its Kruskal reconstruction tree with internal nodes labeled by level (right). Thick edges lead to preferred children. The path ending at leaf 1 consists of the node of level 1; its parent node, of level 3, prefers the subtree with representative 3. The pointer is stale, and correspondingly the edge of vertex 1 is a down edge ().
Lemma 11. Let be a non-root vertex and .
(i) The preferred path ending at consists of the nodes below that contain , and lies in the preferred child of . Thus is a path-parent pointer: it names a leaf of the preferred subtree of the parent node , though not necessarily its representative.
(ii) is stale if and only if the edge of is a down edge.
Proof. (i) A node containing has rep exactly when owns no node inside , that is, when lies strictly below . Let be the child of that contains . Its internal nodes are owned by its leaves other than , one each, so every leaf of owns a node inside , and rep lies in the other child. That child also contains , because is the node of the edge and joins the components of and .
(ii) If , then contains and lies below , so owns a node inside and is not its representative. Otherwise is the root or , so owns no node inside , and by uniqueness.
Theorem 12. Let be connected with distinct edge costs.
(i) A skip changes no preferred child.
(ii) A rotation of changes exactly one preferred child: that of the node owned by before the rotation, which turns towards .
(iii) After , every node on the path from to the root of prefers the child containing . The number of case-(A) rotations equals the number of nodes on this path that did not prefer 's side before the access, that is, the number of preferred-child changes in a link-cut tree access to on . Case-(C) rotations change preferred children only off this path.
Proof. Ownership, and hence every representative and preferred child, is determined by the costs alone.
(i) A skip changes no cost.
(ii) Let be the node of the edge , at level . If is not the root, let be the node of the edge , at level . Before the rotation, owns and owns , or nothing if is the root. After the rotation, the owners are exchanged, and no other ownership changes. Consider an internal node . If does not contain , then contains neither nor , so its internal nodes and their owners are unchanged, and so is rep. If contains , the set of owners of its internal nodes is unchanged, and so is rep. Otherwise and owns nothing inside . Then rep before the rotation and rep after it. If , the leaves and lie in the same child of , so the preferred child of is unchanged. If , they lie in different children, and the preferred child of turns towards .
(iii) At the end of the access, is the root of and owns no node. Hence is the representative of every node that contains it. A case-(C) rotation turns the node owned by , at level . This node does not contain , because every path from to uses the edge of , whose cost exceeds the node's level. A case-(A) rotation turns the node owned by , which contains , towards . So nodes on the path of change only by case-(A) rotations, and each changes at most once, towards . Every node on the path that did not prefer 's side therefore changes exactly once, and no other node on the path changes.
Theorem 12 accounts for the efficiency of the structure. In a link-cut tree, every preferred-child change requires splaying in an auxiliary tree to find where the path-parent pointer attaches. Here, the change is a single rotation, because the pointer names a leaf rather than a position in an auxiliary tree. As a consequence, pointers become stale when the representative of a path changes, and by Theorem 11 the algorithm sees a stale pointer as a down edge. A skip of replaces by another leaf of the same preferred subtree, since . After a skip in case (D) the pointer is fresh, because the new parent has a larger cost; after a skip in case (B) or (C) it may still be stale. The skips thus shortcut stale pointers without changing or its preferred children, in a way similar to path halving in union-find [9]. Insertions, unlike accesses, change , so the usual bound on preferred-child changes in link-cut trees does not transfer directly.
Informally, if all pointers were fresh, contracting each preferred path to its bottom leaf would turn into the virtual tree of a link-cut tree. Stale pointers attach a path to another leaf of the right subtree, so is a lazily maintained version of that tree, and is an analogue of the rank potential of Sleator and Tarjan [5].
6 The folklore structure
Figure 4 shows the folklore BottleneckTree [6], adapted to int costs. It uses the same representation and moves but organizes an access top-down. Procedure compress first recurses to the root. On the way back, at each down edge, it rotates the parent of upwards over all ancestors whose cost does not exceed , and then lets skip once. Finally, reroot rotates to the root.
We measure the work of the folklore BottleneckTree as the number of calls of compress plus the number of iterations of the loop in reroot; each takes constant time.
int AddEdge(int x, int y, int c) { compress(x); rroot(x); compress(y); rroot(y); assert(link[x] == y); if (cost[x] > c) swap(cost[x], c); return c; }
int Query(int x, int y) { compress(x); rroot(x); compress(y); rroot(y); return cost[x]; }
void compress(int x) { if (link[x] == -1) return; compress(link[x]); rroot(link[x], cost[x]); if (cost[link[x]] <= cost[x]) link[x] = link[link[x]]; }
void rroot(int x, int c = INF + 1) { int p = link[x]; while (p != -1 && cost[p] <= c) { swap(cost[p], cost[x]); int g = link[p]; link[p] = x; p = g; } link[x] = p; }
Figure 4: The structure of [6], with the same fields and constructor as in Fig. 2.
Theorem 13. Let be even and . Insert the star AddEdge(v, 0, v) for . Then perform queries on the following sequence of vertices, taken in consecutive pairs. First, for , the vertices congruent to modulo in decreasing order. Then . On these queries, the folklore BottleneckTree performs at least
work. In particular, for its amortized work per query is at least , and per operation, including the insertions, at least , for all sufficiently large .
The choice maximizes the bound; our experiments use . We prove Theorem 13 in Section A, and sketch the mechanism here. After the first phase, every vertex points to . In the second phase, the structure passes through states that repeat up to a shift by one position. Just before vertex is accessed, the vertices below form groups of consecutive vertices with stale pointers, separated by pairs of vertices with up edges, and the vertices above still point positions down. The root path of enters each group at its lowest vertex, so it has length , and the access performs a rollback of two rotations at each of the groups. Each group then loses its lowest vertex to the pair below it and gains a vertex from the pair above it, which restores the pattern one position higher.
Informally, in terms of , each rollback rotates a vertex with a small subtree over ancestors with much larger subtrees, at constant cost. This increases by up to the logarithm of the ratio of their subtree sizes, and the input above causes such rollbacks per access. The rotations of the folklore BottleneckTree also involve a vertex and its parent, so this is not where the two structures differ. The difference is which parent. In the structure of Fig. 2, the vertex rotated over is an original ancestor with its original subtree size (Theorem 6), so the increases of telescope along the root path. In the folklore BottleneckTree, compress(link[x]) has already restructured the ancestors of when the rollback at begins, so this telescoping argument does not apply.
7 Experiments
Implementations. We compare seven implementations:
-
the structure of Fig. 2;
-
the folklore BottleneckTree (Fig. 4);
-
a textbook link-cut tree [5] with edges represented as nodes, splay-based access, and evert by reversal bits;
-
the public AM-tree implementation [2, 10] in its four variants: lazy and strict, each with perch and with stitch linking.
The AM-tree code uses -1 as the stored weight of a root, and its own driver inserts negative weights; we therefore map costs in order-preservingly to negative integers.
Workloads. All workloads are on vertices. The first three consist of insertions with costs drawn uniformly from ; the vertex labels are randomly permuted and the edges are inserted in random order.
-
Random: the endpoints are drawn uniformly from . The final MSF has diameter about 870.
-
Grid: the vertices are placed on a grid; for each vertex , 4 edges join a uniform vertex within distance 2 of to one within distance 5 of (in each coordinate, clamped to the grid). Diameter about 2500.
-
Band: for , 4 edges join a uniform to a uniform (clamped to ). Diameter about 166000.
In Grid-local and Band-local, the same edges are inserted in their natural order, row by row and by increasing , so that consecutive insertions are close in the graph; the labels remain permuted, so they are not close in memory.
- Lag: the input of Theorem 13 with : a star of insertions followed by queries, adversarial for the folklore BottleneckTree.
For the folklore BottleneckTree we also measure the query phase of Lag for .
Correctness. All implementations returned identical answers on all workloads, including 200 000 random queries after each run, which also check the insertion-only workloads. Against a brute-force minimax computation, the structure of Fig. 2 returned the correct value on 517 000 random operations with frequent equal costs. For we enumerated every reachable state with every possible AddEdge, 9.1 million operations including ties; every answer was correct. Over 2.2 million accesses on random and adversarial inputs, every inequality used in the proof of Theorem 7 held, and the largest value of was 4.1, compared with the bound 10.13 of Theorem 7. The statements of Theorem 12 were checked on 297 000 accesses.
| Random | Grid | Band | Lag | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| AMD | Intel | random | local | random | local | AMD | Intel | |||||
| AMD | Intel | AMD | Intel | AMD | Intel | AMD | Intel | |||||
| ours | 1065 | 1695 | 1245 | 1934 | 367 | 477 | 1198 | 1935 | 198 | 271 | 24.9 | 27.3 |
| folklore | 2268 | 3155 | 2214 | 3254 | 618 | 713 | 1846 | 2593 | 299 | 357 | 10642 | 12975 |
| LCT | 12748 | 13790 | 11172 | 12736 | 3579 | 3423 | 10417 | 12097 | 2136 | 1996 | 398 | 319 |
| AM-LP | 776 | 1350 | 1012 | 1759 | 385 | 493 | 1329 | 2322 | 245 | 302 | 25.1 | 25.0 |
| AM-LS | 624 | 1053 | 655 | 1012 | 283 | 369 | 641 | 975 | 318 | 442 | 25.5 | 25.6 |
| AM-SP | 6856 | 7975 | 7872 | 9258 | 2182 | 2292 | 10129 | 12263 | 2012 | 2296 | 29.4 | 31.0 |
| AM-SS | 2446 | 2914 | 2500 | 3077 | 755 | 898 | 2698 | 3227 | 812 | 947 | 31.3 | 31.4 |
Table 2: Running time in milliseconds on the AMD and Intel machines (median of five runs; each entry measured in a fresh process). Random has its edges inserted in random order, Grid and Band in random and in local order. Lag is the adversarial input of Theorem 13. The row folklore is the folklore BottleneckTree, LCT the link-cut tree; AM-LP and AM-LS are the lazy AM-tree with perch and with stitch linking, AM-SP and AM-SS the strict one. All implementations returned identical answers.
Setup. All code was compiled with g++ 13.3 using -O3 -march=native on Ubuntu 24.04 and run single-threaded, pinned to one core, on two Amazon EC2 instances: c7a.2xlarge (AMD EPYC 9R14) and c7i.12xlarge (Intel Xeon Platinum 8488C). All structures use 32-bit costs. Each implementation is compiled into a separate program, because we observed that other code in the same program can change how a structure's main loop is compiled, by up to 50% in running time. Each entry of Table 2 is the median of five runs in a fresh process. To exclude drift, we also ran our structure and the lazy AM-tree variants in 11 interleaved rounds; the median per-round ratios agreed with Table 2 within 7% on the insertion workloads and within 20% on Lag, whose runs take 25 ms.
Results. On the insertion workloads, the folklore BottleneckTree is 1.3–2.1 times slower than our structure, and the link-cut tree is 6.3–12 times slower (Table 2). The strict AM-tree variants, which also bound the worst-case query time, are slower than ours throughout. Against the lazy variants, the outcome depends on the order of insertions. In random order, stitch linking is 1.6–2.0 times faster than ours on all three random-order workloads, and perch linking is 1.3–1.4 times faster on Random and 1.1–1.2 times faster on Grid, but 1.1–1.2 times slower on Band. In local order, perch linking is 3–5% slower than ours on Grid-local, and stitch linking 1.3 times faster; on Band-local, our structure is the fastest of all, and the lazy variants are 1.1–1.2 times slower with perch and 1.6 times slower with stitch linking. On Lag, the folklore BottleneckTree is 430–480 times slower than our structure and the link-cut tree 12–16 times slower, while the AM-tree variants take 0.92–1.3 times our time. From to , the folklore time per query on Lag grows by a factor of about 22, somewhat more than (a factor of 16), while ours changes by at most 18%.
Table 3 explains these results. The running time follows the number of vertices on the root paths that an insertion visits, since each is a dependent memory access: the next vertex is known only after the current one has been read. Our structure reads two arrays per vertex and the AM-tree three, so each vertex costs us less. In random order, our paths are 1.2–3.3 times longer than those of the lazy AM-tree, whose size rule keeps the tree shallow. In local order, the
| Random | Grid | Band | |||
|---|---|---|---|---|---|
| random | local | random | local | ||
| ours | 22.2 | 25.5 | 10.9 | 24.6 | 6.6 |
| AM-LP | 9.7 | 13.0 | 6.6 | 20.2 | 5.1 |
| AM-LS | 6.8 | 8.3 | 4.0 | 11.0 | 10.3 |
Table 3: Average depth walked per insertion: the sum of the depths of the two endpoints just before they are accessed, which is the number of vertices on the root paths that the insertion follows. Measured on instrumented copies of the code, on the inputs of Table 2.
endpoints of a new edge are close to vertices that recent accesses brought near the root, and our paths become 2.3–3.7 times shorter (10.9 and 6.6 vertices). Those of perch linking shrink about as much, and those of stitch linking do not shrink on Band.
The trade-off resembles the one between splay trees [5] and weight-balanced search trees [11]. Like a splay tree, our structure stores no balance information and restructures along every access path. The anti-monopoly rule of the AM-tree is a weight-balance condition with parameter 2/3, which the lazy variant restores only where it is violated. In experimental comparisons of search trees, splay trees are likewise slower than balanced trees on uniformly random accesses and faster on accesses with locality [12], such as sequential access, on which they take linear total time [13].
8 Related work
Link-cut trees [4, 5] support incremental MST in amortized time; top trees [14, 15] and RC-trees [16] give alternatives, and Tarjan and Werneck [17] compare these structures experimentally, including on online MSF. The fully dynamic problem, with deletions, requires substantially more machinery [18, 19], and offline variants have simpler solutions [20]. Batch-incremental and sliding-window variants were studied by Anderson, Blelloch and Tangwongsan [3].
The D-tree [21] maintains rooted spanning trees for fully dynamic connectivity queries. Closer to our setting, the OEC-forest [1] maintains a rooted tree with the path maxima of the MSF and uses the transformation behind Theorem 1 for temporal connectivity. The AM-tree [2] added the anti-monopoly rule and obtained amortized bounds, with worst-case query bounds in its strict variant. As discussed in the introduction, our structure differs from it mainly in the order of operations within an access, and it stores no sizes. The AM-tree offers things ours does not: its queries are read-only once sizes are calibrated, its strict variant bounds the worst-case query time, and it has a persistent version for historical queries on temporal graphs. Because every access of our structure restructures the tree, persistence would be costly for it. In the Kruskal reconstruction tree, also known as the Cartesian tree of the MSF edges [8], an insertion merges two root paths, as in mergeable trees [22]. The advancing of stale pointers resembles path halving in union-find [9] and union-find with deletions [23].
The representation also appears in competitive programming. A January 2020 solution by Basu [24] to an incremental MST problem [25] merges the root paths of the two endpoints of a new edge, guided by subtree sizes, in much the same way as the stitch linking of the AM-tree, but without rebalancing and without a bound. The folklore BottleneckTree grew out of it, replacing the sizes by rotations. A structure for the same problem with a claimed bound was described in a Codeforces blog post [26]. It does not come with a proof.
9 Conclusion and open problems
The structure of Fig. 2 solves incremental MST and bottleneck queries in amortized time with two arrays and one loop. In practice it is 1.3–2.1 times faster than the folklore BottleneckTree on insertions and 6.3–16 times faster than an explicit link-cut tree; the lazy AM-tree variants are faster when edges arrive in random order, and ours can be faster when consecutive insertions are close in the graph (Section 7). Its analysis follows from one observation: during an access, the ancestors of the current vertex are untouched, so every rotation is over an original ancestor with its original subtree size, and the potential gains telescope.
Optimality. The bound is optimal for structures that only compare costs. Insert keys as the edges of a path, then insert edges of cost (any cost below all keys), each between the two current endpoints of the path. Each insertion closes a cycle through all remaining keys and evicts the largest, whose endpoints become the new endpoints. The evicted costs come out in decreasing order, so operations sort keys, and some operation takes amortized time. In the cell-probe model, the bound of Pătrașcu and Demaine [27] for dynamic connectivity gives a related bound for dynamic MSF with deletions.
Open problems.
-
Our bounds are amortized. Is there a comparably simple structure with worst-case queries, as in the strict AM-tree?
-
With edges in random order, the root paths followed by our structure are up to 3.3 times longer than those of the lazy AM-tree (Table 3). Is there an equally simple structure without sizes that keeps paths as short on such inputs?
-
By Theorem 12, the case-(A) rotations of an access are the preferred-child changes on the Kruskal reconstruction tree, the quantity behind Wilber's first lower bound [28] and Tango trees [29]. Does the structure satisfy analogues of the splay-tree theorems, such as sequential access or working set, and is there a meaningful notion of dynamic optimality for path-maxima trees?
Acknowledgments
We thank Rajarshi Basu, whose January 2020 solution to the problem Transport Rutier [25] on the infoarena judge contained the first version of this structure; the question of its complexity started this line of work. We used an AI assistant (Claude) for experiments, verification scripts and editing; all results were checked by the authors.
References
[1] J. Song, D. Wen, L. Xu, L. Qin, W. Zhang, and X. Lin. On querying historical connectivity in temporal graphs. Proceedings of the ACM on Management of Data, 2(3):1–25, 2024.
[2] X. Ding, Y. Gu, and Y. Sun. New algorithms for incremental minimum spanning trees and temporal graph applications. In Proc. SIAM Conference on Applied and Computational Discrete Algorithms (ACDA), pages 293–307, 2025. arXiv:2504.04619.
[3] D. Anderson, G. E. Blelloch, and K. Tangwongsan. Work-efficient batch-incremental minimum spanning trees with applications to the sliding-window model. In Proc. SPAA, pages 51–61, 2020.
[4] D. D. Sleator and R. E. Tarjan. A data structure for dynamic trees. Journal of Computer and System Sciences, 26(3):362–391, 1983.
[5] D. D. Sleator and R. E. Tarjan. Self-adjusting binary search trees. Journal of the ACM, 32(3):652–686, 1985.
[6] A. Budău and L. Bicsi. BottleneckTree.h. KACTL fork, 2021. https://github.com/bicsi/kactl/blob/master/content/graph/BottleneckTree.h.
[7] B. Allen and I. Munro. Self-organizing binary search trees. Journal of the ACM, 25(4):526–535, 1978.
[8] E. D. Demaine, G. M. Landau, and O. Weimann. On Cartesian trees and range minimum queries. Algorithmica, 68(3):610–625, 2014.
[9] R. E. Tarjan and J. van Leeuwen. Worst-case analysis of set union algorithms. Journal of the ACM, 31(2):245–281, 1984.
[10] X. Ding, Y. Gu, and Y. Sun. AM-tree source code. https://github.com/ucrparlay/AM-tree, accessed November 2026.
[11] J. Nievergelt and E. M. Reingold. Binary search trees of bounded balance. SIAM Journal on Computing, 2(1):33–43, 1973.
[12] B. Pfaff. Performance analysis of BSTs in system software. In Proc. SIGMETRICS/Performance, pages 410–411, 2004.
[13] R. E. Tarjan. Sequential access in splay trees takes linear time. Combinatorica, 5(4):367–378, 1985.
[14] S. Alstrup, J. Holm, K. de Lichtenberg, and M. Thorup. Maintaining information in fully dynamic trees with top trees. ACM Transactions on Algorithms, 1(2):243–264, 2005.
[15] R. E. Tarjan and R. F. Werneck. Self-adjusting top trees. In Proc. SODA, pages 813–822, 2005.
[16] U. A. Acar, G. E. Blelloch, and J. L. Vittes. An experimental analysis of change propagation in dynamic trees. In Proc. ALENEX, pages 41–54, 2005.
[17] R. E. Tarjan and R. F. Werneck. Dynamic trees in practice. ACM Journal of Experimental Algorithms, 14:4.5, 2009.
[18] G. N. Frederickson. Data structures for on-line updating of minimum spanning trees, with applications. SIAM Journal on Computing, 14(4):781–798, 1985.
[19] J. Holm, K. de Lichtenberg, and M. Thorup. Poly-logarithmic deterministic fully-dynamic algorithms for connectivity, minimum spanning tree, 2-edge, and biconnectivity. Journal of the ACM, 48(4):723–760, 2001.
[20] D. Eppstein. Offline algorithms for dynamic minimum spanning tree problems. Journal of Algorithms, 17(2):237–250, 1994.
[21] Q. Chen, O. Lachish, S. Helmer, and M. H. Böhlen. Dynamic spanning trees for connectivity queries on fully-dynamic undirected graphs. Proceedings of the VLDB Endowment, 15(11):3263–3276, 2022.
[22] L. Georgiadis, H. Kaplan, N. Shafir, R. E. Tarjan, and R. F. Werneck. Data structures for mergeable trees. ACM Transactions on Algorithms, 7(2):14, 2011.
[23] H. Kaplan, N. Shafir, and R. E. Tarjan. Union-find with deletions. In Proc. SODA, pages 19–28, 2002.
[24] R. Basu. Solution to Transport Rutier, infoarena submission 2524286, January 2020. https://www.infoarena.ro/job_detail/2524286?action=view-source.
[25] M. Ciucu. Transport Rutier. Problem of the All You Can Code contest, 2008. https://infoarena.ro/problema/rutier.
[26] not_amir. Maintaining MST with online edge insertions — no LCT needed. Codeforces blog entry 130107, 2024. https://codeforces.com/blog/entry/130107.
[27] M. Pătrașcu and E. D. Demaine. Logarithmic lower bounds in the cell-probe model. SIAM Journal on Computing, 35(4):932–963, 2006.
[28] R. Wilber. Lower bounds for accessing binary search trees with rotations. SIAM Journal on Computing, 18(1):56–67, 1989.
[29] E. D. Demaine, D. Harmon, J. Iacono, and M. Pătrașcu. Dynamic optimality—almost. SIAM Journal on Computing, 37(1):240–251, 2007.
A Proof of Theorem 13
The proof follows the state of the folklore BottleneckTree exactly, access by access; a query performs the access of its first vertex and then the access of its second, so it suffices to follow accesses. It has four steps.
(1) The state before every access has a simple shape, which we call chain form: a sorted chain of vertices ending at the root, and every other vertex pointing to a smaller vertex.
(2) One access transforms a chain form by an explicit rule (Theorem 14).
(3) The first phase of queries produces a specific chain form (Theorem 15).
(4) After a short warm-up of the second phase, the state before the access of is a fixed pattern , cut off at 0, and the access turns it into the same pattern shifted by one position, (Theorem 16). For large enough , each such access costs exactly . Figure 5 shows the pattern for .
Throughout, and denote the largest element of a set below and the smallest element above .
Chain form. A state is in chain form if there is a set with , and every vertex has a pointer , such that:
- the largest element of is the root, and every other has , so the elements of form a chain of up edges ending at the root;
• every has and .
We write such a state as . In Fig. 5, the elements of are drawn as squares and the pointers as arrows.
One access. In chain form, the root path of a vertex first follows pointers downwards until it reaches , and then climbs the chain . On the way back up from this descent, the folklore code performs a rollback of a vertex whenever it can rotate over a run of chain elements; all of them except the lowest leave and point to , and joins . The following lemma states exactly which elements move.
Lemma 14 (Access in chain form). Let be in chain form and . Let be the vertices outside reached from by following pointers, and let . Then followed by transforms as follows. Process in this order, with the current set:
(a) let (where ), the vertex that points to;
(b) let if , and if ;
(c) let if , and otherwise;
(d) if , every with leaves with , and joins ;
(e) in any case, set .
Finally, z joins B.
Proof. The root path of is followed by the elements of from upwards. Along that chain the costs increase, so for every chain vertex , changes nothing: the loop of stops at once, and does not skip. The calls then return for in this order. We show by induction that each implements step of the rule and leaves and , with untouched.
Consider . By induction, is either , or it is outside with . In both cases the loop walks up the chain , from if and from otherwise. A chain element has cost , which is at most exactly when ; the root has cost . Hence the loop rotates over the chain elements in , excluding itself if . Afterwards each is a child of ; has the former cost of , the former cost of , which is , for ; and has link and cost . If , the former cost of is , so all leave with pointer , and stays in with successor . If and , then gets link and cost and stays in with successor , the other leave with pointer , and joins with successor . If , nothing changes. This is the rule. In every case, or afterwards. If , then and keeps . Otherwise , and skips to . No element between and was added, so is still .

Figure 5: The steady pattern for (), drawn on the vertices ; it is exactly the state of the folklore BottleneckTree before the accesses of 44 and 45. Squares are the elements of , which form a chain of up edges; a circle has cost and an arrow to its pointer . In , the groups and point 4 and 2 positions down, the pairs , and everything up to 33 are in , and the vertices from 44 on point 6 down. The access of 44 follows the thick arrows and rolls 34 and 38 back into ; the result is the same pattern one position higher.
For , the same argument with applies, since every chain element below the root has cost at most . Finally, rotates over the root , which gets link and cost , so joins as the new root.
The first phase. The first phase accesses the residue classes modulo from the top down. Its effect is that every vertex ends up pointing exactly positions below itself.
Lemma 15 (First phase). After the star and the first phase, the state is in chain form with , for , and for .
Proof. Each rotates over the root 0 and then 0 back over , and the swap gives the cost . After the star, the state is in chain form with and for all .
We claim that before the access of a vertex of class , the state is in chain form with , where is the last vertex accessed in class (absent if ) and is the vertex accessed before in class (absent if is the first). Vertices that have not been accessed have pointer 0, and every accessed vertex other than and already has its final pointer.
Let be accessed. Its root path is , omitting absent vertices, and has pointer 0. If is absent or , the call changes at most the pointer of : if is present, skips from 0 to , since ; otherwise and nothing happens. Then rotates over the remaining vertices of its root path. Afterwards (or ), and has cost and pointer . If , then changes nothing, since , and rotates over 0, and . Afterwards , has pointer , and has pointer . The vertex accessed next is the first of class , so the claim holds with . The last access, of , rotates 0 over and , which then point to .
The steady pattern. Before the access of in the second phase, the vertices below form groups of consecutive vertices, whose pointers jump positions down; consecutive groups are separated by a pair of elements of , the two vertices just below are in , and below the smallest group every vertex is in . Above , every vertex still points positions down. Formally, let . For an integer , define and for . The pattern is the chain-form state on the integers in which
the vertices of the group have pointer for , and every has pointer . Each consists of consecutive vertices. For example, for and we get , , and , so contains everything up to 33 and the pairs and , and the groups are and (Fig. 5). For vertices, let be the chain form on with set and pointers ; it cuts the infinite pattern off at 0.
The next lemma says that one access shifts the pattern by one position. In the example, the access of 44 follows the pointers . On the way back up, no element of B moves at 34; only the pointer of 34 advances from 32 to 33. At 38, the code rolls 34 back over 33 and 36: 36 leaves B and points to 34, which joins B. At 44, it rolls 38 back over 37 and 42: 42 leaves B and points to 38, which joins B. Finally 44 joins B. The result is .
Lemma 16 (Shift by one). For every , applying the rule of Theorem 14 to with gives , and the rule commutes with .
Proof. Let , the lowest vertex of . The pointers lead from to and then to . At step , and , so nothing is removed, and gets pointer . At step , , and , so leaves with pointer , and joins . Finally joins . The new values satisfy the same recurrence from . The new pairs and are . The new group is without and with added, whose pointer is below it. This is .
For the commutation, write . For , we have if and only if , and ; also . In , the pointers from follow while these are positive, and the first non-positive one is replaced by . Consider step of the rule on . Since , we have , and holds if and only if has an element in , in which case . If , then , and every vertex the step changes are non-positive, so does not see the step. If , the same step on has , and, in both cases of (c), . If , the step on changes only non-positive vertices and sets , while the step on removes nothing and sets . If , then if and only if ; the removed set is the positive part of , and its new pointer is the clamped pointer ; belongs to afterwards exactly when joins or ; and . Finally, joins both sets. Hence applying the rule to gives of the result on . We also checked this mechanically (see below).
Counting the work. It remains to check that the second phase reaches the pattern, and to count the work of one access in the pattern: one call of compress for each of the 3L/2 vertices on the root path, two rotations for each of the K rollbacks, and one final rotation in reroot.
Proof of Theorem 13. Before access of the second phase, the root is , so Theorem 14 applies. From the state of Theorem 15, the accesses follow the pointer and only add to ; the access of follows and removes , which get pointer 0. The result is , which is . By Theorem 16, the state before access is for all .
From the recurrence, . If , then , so does not affect the root path of , which consists of , the pair , and the pairs above it: vertices. By the proof of Theorem 16, the access rotates over two vertices at each of the steps , and once in . Its work is therefore . The sequence has vertices, so the queries cover the accesses up to , and of them satisfy this condition.
For we have and , so the work per query is at least , and .
We checked each lemma mechanically. Theorem 14 was compared with the code on 300 000 random chain-form states, and Theorem 15 and Theorem 16 were checked state by state for all even and several n for each; the work of every access with was exactly .