Fully Dynamic Connectivity in $O(\log n(\log\log n)^2)$ Amortized Expected Time

Dynamic connectivity is one of the most fundamental problems in dynamic graph algorithms. We present a randomized Las Vegas dynamic connectivity data structure with $O(\log n(\log\log n)^2)$ amortized expected update time and $O(\log n/\log\log\log n)$ worst case query time, which comes very close to the cell probe lower bounds of Patrascu and Demaine (2006) and Patrascu and Thorup (2011).


Introduction
The dynamic connectivity problem is one of the most fundamental problems in dynamic graph algorithms. The goal is to support the following three operations on an undirected graph algorithms always answer Conn? queries correctly but their running time is a random variable.
In contrast, the running time of a Monte Carlo algorithm is guaranteed deterministically, but it only answers Conn? queries correctly with high probability. All known dynamic connectivity algorithms maintain a spanning forest of as a sparse certi cate of connectivity. If is public then the sequence of Insert and Delete operations may depend on , and may therefore depend on random bits generated earlier by the data structure. When is private the Insert/Delete sequence is selected obliviously.
In this paper we prove near-optimal bounds on the amortized complexity of dynamic connectivity in the Las Vegas randomzed model, with a public connectivity witness.
T H E O R E M 1 .1. There exists a Las Vegas randomized dynamic connectivity data structure that supports insertions and deletions of edges in amortized expected (log (log log ) 2 ) time, and answers connectivity queries in worst case (log /log log log ) time. The time bounds hold even if the adversary is aware of the internal state of the data structure. In particular, the data structure maintains a public spanning forest as a connectivity witness.

A Brief History of Dynamic Connectivity Data Structures
Worst Case Time. Frederickson [8] developed a dynamic connectivity structure in the strictest model-deterministic worst case time-with ( √ ) update time and (1) query time. Eppstein, Galil, Italiano, and Nissenzweig [6] showed that the update times for many dynamic graph algorithms could be made to depend on rather than , provided they maintain an ( )edge witness of the property being maintained, e.g., a spanning forest in the case of dynamic connectivity. Together with [8], Eppstein et al.'s reduction implied an ( √ ) update time for dynamic connectivity, a bound which stood for many years. Kejlberg, Kopelowitz, Pettie, and Thorup [15] simpli ed Frederickson's data structure, and improved the update time of [8,6] to √︃ (log log ) 2 log . Recently Chuzhoy, Gao, Li, Nanongkai, Peng, and Saranurak [5] improved the worst case update time to (1) .
Kapron, King, and Mountjoy [14] gave a Monte Carlo randomized structure with update time ( log 5 ) and one-sided error 1 probability − . Their data structure maintains a private connectivity witness, i.e., it keeps a spanning tree, but the adversary controlling Insert and Delete operations does not have access to the spanning tree. The update time was later improved to ( log 4 ) independently by Gibb et al. [9] and Wang [21], and Wang further reduced the time for Insert to ( log 3 ). Nanongkai, Saranurak, and Wul -Nilsen [17] discovered a Las Vegas randomized structure with (1) update time that maintains a public connectivity witness. This data structure was recently derandomized [5], leading to a deterministic (1) dynamic connectivity algorithm maintaining a public witness. 1 An error occurs from reporting that two vertices are disconnected when they are actually connected.

Preliminaries
In this section we review some basic concepts and invariants used in prior dynamic connectivity algorithms [10,12,20,22].
Witness Edges, Witness Forests, and Replacement Edges. A common method for supporting connectivity queries is to maintain a spanning forest F of called the witness forest, together with a dynamic connectivity data structure on F (see Theorem 2.1 below). Each edge in the witness forest is called a witness edge, and all other edges are called non-witness edges.
Deleting a non-witness edge does not change the connectivity.
Update Time and Query Time. When describing the dynamic connectivity data structure we only focus on the (amortized) running time of the update operations. Once this time bound is xed, Theorem 2.1 provides a fast query time, which, according to Pǎtraşcu and Demaine [1], cannot be unilaterally improved.

T H E O R E M 2 .1 (Henzinger and King [10]).
For any function ( ) = Ω(1), there exists a dynamic connectivity data structure for forests with ( ( ) log ) update time and (log /log ( )) query time.

P R O O F S K E T C H .
Maintain an Euler tour of each tree in the witness forest and a balanced ( )-ary rooted tree over the Euler tour elements. The height of each rooted tree is (log ( ) ).
A witness edge insertion/deletion imposes (1) changes to the Euler tour, which necessitates ( ( ) log ( ) ) time to update the rooted trees. A query Conn?( , ) nds the representative copies of and in the Euler tours, walks up to their respective roots, and checks if they are equal.
The di culty in maintaining a dynamic connectivity data structure is to nd a replacement edge when a witness edge ∈ F is deleted, or determine that no replacement edge exists. To  Endpoints. The endpoints of an edge = { , } are the pairs , and , . At some stage in our algorithm we sample a random endpoint from a set of endpoints incident to some ⊂ .
An edge { , } with , ∈ could contribute zero, one, or two endpoints to , i.e., the endpoints of an edge are often treated independently. An endpoint , is said to be touching the nodes ∈ˆfor all ∈ [1, max ].

Computational Model and Lookup Tables
We assume a standard (log )-bit word RAM with the usual repertoire of 0 instructions.
The data structure uses some non-standard operations on packed sequences of (log log )-bit oating point numbers, which we can simulate by building small lookup tables with size ( ), for some ∈ (0, 1). Since the initial graph is empty, the ( ) sized lookup tables can be built on-the-y, with their cost amortized through the operations. 2 2 As long as the number of graph updates is ≤ , all edge depths are at most log . Hence, for each 0 ≤ ≤ log log , after the = 2 2 -th graph update, the data structure rebuilds the lookup tables of size ( ). The time cost for building the lookup tables during the first operations is bounded by log log =0 1 2 = ( ), which is amortized (1) per update.

Miscellaneous
Almost Uniform Sampling. We say that an algorithm samples from a set (1+ (1))-uniformly at random, if, for any element ∈ , the probability of being returned is (1 + (1))/| |. (In our algorithm, the (1) term is roughly 1/log , and | | is at most polynomial in .) Mergeable Balanced Binary Trees. Some parts of our data structure (see Section 7) use othe-shelf mergeable balanced binary trees. They should support leaf-insertion and leaf-deletion on in (log | |) time, and the merger of two trees 1 , 2 in (log | 1 | + log | 2 |) time. The merge operation may create and delete internal nodes as necessary to ensure balance. These trees do not store elements from a totally ordered set, and do not need to support a search function.

Overview of the Algorithm
As in [12,22], our goal is to restore Invariant 2.2 after each update operation.
In the rest of this section, we provide an overview of the algorithm. The underlined parts of the text refer to primitive data structure operations supported by Lemma 3.1, presented in Section 3.3.
The Data Structure. The hierarchy H naturally de nes a rooted forest (not to be confused with the maximum spanning forest), which is called the hierarchy forest, and contains several hierarchy trees. We abuse notation and say that H refers to this hierarchy forest, together with several auxiliary data structures supporting operations on the hierarchy forest. The nodes in H are the -components for all ∈ [1, max ]. The roots of the hierarchy trees are nodes inˆ0, representing 1-components. The set of nodes at depth in H is exactlyˆ. The set of children of a node ∈ˆis { +1 ∈ˆ+ 1 | = }. The leaves are nodes inˆm ax = . See Figure 1 for an example. The nodes in H are called H -nodes, and the roots are called H -roots.

Insertion
To execute an Insert( , ) operation, where = { , }, the data structure rst sets = 1. If connects two distinct components in (which is veri ed by a connectivity query on F ), then the data structure accesses two H -roots 0 and 0 , merges 0 and 0 and is inserted into H (and F ) as a 1-witness edge. Otherwise, is inserted into H as a 1-non-witness edge.

Deletion
To execute a Delete( , ) operation, where = { , }, the data structure rst removes from H . Let = . If is an -non-witness edge, then the deletion process is done. If is an -witness edge, the deletion of could split an -component. In this case, the deletion algorithm rst  focuses on nding a replacement edge that has depth = . In Section 3.2.3 we extend our algorithm to nd a replacement edge of any depth, while preserving the Maximum Spanning Forest Property of Invariant 2.2.
The rest of the deletion process focuses on nding a replacement edge to reconnect and into one -component. This process has two parts, explained in detail below: (1) establishing the two components and , and (2) nding a replacement edge. Notice that and do not necessarily correspond to H -nodes.

Establishing Two Components
To establish the two components and created by the deletion of , the data structure executes in parallel two graph searches onˆ− {{ , }} starting from and . To implement a search, we mark unexplored and insert it into a queue. We repeatedly remove any unexplored ( + 1)-component from the queue, mark it explored, and enumerate all -witness edges with one endpoint in . All new ( + 1)-components touching these edges are marked unexplored and inserted into the queue. The two searches are carried out in parallel until one of the connected components is fully scanned. By fully scanning one component, the weights of both components are determined, since ( −1 ) = ( ) + ( ). Without loss of generality, assume that ( ) ≤ ( ), and so by Invariant 2.2, ( ) ≤ ( −1 )/2 ≤ /2 .

Witness Edge Promotions.
The data structure promotes all -witness edges touching nodes in and merges all ( + 1)-components contained in into one ( + 1)-component with weight ( ). This is permitted by Invariant 2.2, since ( ) ≤ /2 . The merged ( + 1)-component has the node −1 as its parent in H . See Figure 2. . To di erentiate between versions of components before and after the merges, we use bold fonts to refer to components after the merges take place. Thus, the ( + 1)-component contracted from all ( + 1)-components inside is denoted u i . Similarly, the graphˆafter merging some of its nodes is denoted byĜ i .
Having contracted the ( + 1)-components inside into u i , we now turn our attention to identifying whether the deletion of disconnects u i from inĜ i .

Finding a Replacement Edge
Notice that by de nition ofĜ i and −1 , a depth-edge is a replacement edge in if and only if it is an -non-witness edge with exactly one endpoint ∈ such that = u i . To nd a replacement edge, the data structure executes one or both of two auxiliary procedures: the sampling procedure and the enumeration procedure.
Intuition. Consider the following two situations. In Situation A at least a constant fraction of the -non-witness edges touching u i have exactly one endpoint touching u i , and are therefore eligible replacement edges. In Situation B a small fraction (maybe zero) of these edges have exactly one endpoint in u i . If the algorithm magically knew which situation the algorithm is in and could sample -non-witness endpoints uniformly at random then the problem is straightforward to solve: In Situation A the algorithm iteratively samples an -non-witness endpoint and tests whether the other endpoint is in u i . As we will see, each test costs (log (log log )) time. The expected number of samples used to nd a replacement edge in this situation is (1) and so the time cost is charged (in an amortized sense) to the deletion operation. In Situation B the algorithm enumerates and marks every -non-witness endpoint touching u i . Any edge with one mark is a replacement edge and any with two marks may be promoted to depth + 1 without violating Invariant 2.2. Since a constant fraction of the edges will end up being promoted, the amortized cost of the enumeration procedure is zero, so long as the enumeration and promotion cost is ((log log ) 2 ) per endpoint.
There are two technical di culties with implementing this idea. First, the set of -nonwitness edges incident to u i is a dynamically changing set, and supporting fast (almost-)uniformly random sampling on this set is a very tricky problem. Second, the algorithm does not know in advance whether the current situation is Situation A or Situation B. Notice that it is insu cient to draw (1) random samples and, if no replacement edge is found, to deduce that the algorithm is in Situation B. Since the cost of enumeration is so high, the algorithm cannot a ord to mistakenly think that it is in Situation B.
Primary and Secondary Endpoints. The di culty with supporting random sampling is dynamic updates: when -non-witness edges are inserted and deleted from the pool due to promotions, the algorithm responds to each such insertion/deletion with updating Ω(log ) parts of the data structure that enables fast random sampling. Thus, the cost of updating each part needs to be relatively low in order to obtain the desired time bounds.
Our solution is to maintain two endpoint types for -non-witness edges: primary and secondary. A newly promoted -non-witness edge has two -secondary endpoints and when an -secondary endpoint , is enumerated (see the enumeration procedure below), the data structure upgrades , to an -primary endpoint. The motivation for using two types of endpoints is that the algorithm never samples from the set of -secondary endpoints, which are only subject to individual insertions, but only the set of -primary endpoints, which are subject to bulk inserts/deletes. The bulk updates to -primary endpoints are su ciently large (in an amortized sense) to pay for the changes made to the part of the data structure that supports random sampling.
Notice that each edge undergoes up to max promotions and up to 2 max endpoint upgrades.
Since our goal is to obtain an (log (log log ) 2 ) amortized insertion cost, we are able to charge each promotion or upgrade ((log log ) 2 ) units of time.
The Sampling Procedure. This is the only procedure in our algorithm that uses randomness.
The sampling procedure can be viewed as a two-stage version of Henzinger and Thorup [11], with some complications due to primary and secondary types. We give a simple sampling procedure that either provides a replacement edge or states that, with high enough probability, the fraction of -primary endpoints touching that belong to replacement edges is small.
Let be the number of -primary endpoints touching u i . The data structure rst estimates up to a constant factor and then invokes the batch sampling test, which (1 + (1))-uniformly samples (log log ) -primary endpoints touching u i . If an endpoint of a replacement edge is sampled, then the sampling procedure is terminated, returning one of the replacement edges. Otherwise, the data structure invokes the second batch sampling test, which (1 + (1))uniformly samples (log ) -primary endpoints touching u i . The purpose of this step is not to nd a replacement edge, but to increase our con dence that there are actually few replacement edges. (Since otherwise it is hard to obtain good amortized cost.) If more than half of these endpoints belong to replacement edges, then the sampling procedure is terminated and one of the replacement edges is returned. Otherwise, the algorithm concludes that the fraction of the non-replacement edges touching u i is at least a constant, and invokes the enumeration procedure.
The Enumeration Procedure. The data structure rst upgrades all -secondary endpoints touching u i to -primary endpoints, then enumerates all -primary endpoints touching u i and establishes for each such edge the number of its endpoints touching u i (either one or both).
An edge is a replacement edge if and only if exactly one of its endpoints is enumerated. Each non-replacement edge encountered by the enumeration procedure has both endpoints in an ( +1)-component, namely u i , and can therefore be promoted to a depth ( + 1)-non-witness edge (making both endpoints secondary), without violating Invariant 2.2. As part of the promote and upgrade operations, the algorithm completely rebuilds the part of the data structure supporting random sampling on the -primary endpoints touching u i .
Since the enumeration procedure is only invoked when the algorithm concludes that (before the enumeration process) the fraction of the non-replacement edges touching u i is at least a constant, the cost of rebuilding the data structure component supporting random sampling is charged to promoting the (su ciently large number of) non-replacement edges. Implementation. If a depth-replacement edge exists, then −1 is still an -component and the algorithm converts from an -non-witness edge to an -witness edge. Otherwise, and form two distinct -components inĜ i . In this case, the data structure splits −1 into two sibling nodes (or two H -roots, if = 1): a new node u i−1 representing whose only child is u i , and v i−1 representing whose children are the rest of the ( + 1)-components in . If = 1 then the algorithm is done. Otherwise, the algorithm sets ← − 1, conceptually demoting , and repeats the procedure as if were deleted at depth − 1.       (1) Add or remove an edge with a given edge depth and endpoint type (log (log log ) 2 ) .

The Backbone of the Data Structure
(2) Given a set of sibling H -nodes or H -roots, merge them into a single node u i , and then promote all -witness edges touching u i to ( + 1)-witness edges −Ω((| | − 1) (log log ) 2 ) .

The Main Modules of the Data Structure
To support Lemma 3.1, the data structure utilizes ve main modules, some of which depend on each other: (1) the H -leaf data structure, (2) local trees, (3) the notion of an induced ( , )-forest,

The H-Leaf Data Structure
The H -leaf data structure supports several operations that act on an individual vertex. Let be a vertex (an H -leaf), ∈ [1, max ] be a depth, and ∈ {witness, primary, secondary} be an endpoint type. The H -leaf data structure supports insertion or deletion of an endpoint (of an edge incident to ) with depth and type . Moreover, the H -leaf data structure supports enumeration of all endpoints incident to with depth and type , and selecting one such endpoint uniformly at random.
Supporting these operations in (1) amortized time (plus time linear in the output) is straightforward. Simply pack the endpoints with depth and type ( , ) in a dynamic array.
Dynamic arrays can be implemented deterministically to support incrementing/decrementing the length of the array in (1) amortized time.

The Local Trees
A local tree is a specially constructed binary tree, whose root is associated with an H -node and whose leaves are associated with the H -children of . By composing the local trees with H , we can view the result as a single binary tree of height at most (log log log ). The purpose of this binarization is to provide an e cient infrastructure for supporting navigation within H .
The local tree operations are detailed in Section 7 and summarized in Lemma 7.8.

The Induced ( , )-Forest
The purpose of the ( , )-forests is to support e cient enumeration of all endpoints of a given type that touch a given H -node. For a given edge depth ∈ [1, max ] and endpoint type ∈ {witness, primary, secondary}, an H -leaf is an ( , )-leaf if has an incident endpoint with depth and type . An H -node ∈ˆhaving an ( , )-leaf in its subtree is an ( , )-root. is an ( , )-root, has more than one child in (so is called an ( , )-branching node), or is an H -child of an ( , )-branching node but has only one H -child in . In this case we call a single-child ( , )-node.
Notice that an ( , )-root may or may not be an ( , )-branching node.
Storing ( , )-status. Each node in ∈ H stores two bitmaps of size 3 max = (log ) each.
The rst indicates for each ( , ) pair whether is an ( , )-node, and if so, the second indicates whether is an ( , )-branching node or not.
Operations on ( , )-forests. A conceptual edge between an ( , )-node and its ( , )-parent or ( , )-child need not be maintained explicitly. The two components of our data structure that simulate these edges are the shortcut infrastructure and the local trees. In particular, the shortcut infrastructure supports e cient traversal from a single-child ( , )-node to its unique ( , )-child, while the local trees support e cient enumeration of all the ( , )-children of an ( , )-branching node. Since the implementation of traversal and navigation operations on ( , )-forests utilizes local trees which are introduced and de ned in Section 7, we defer the discussion of ( , )-forests and their detailed implementation to Section 8.2 (see Lemma 8.1).

The Shortcut Infrastructure
The purpose of shortcuts is to facilitate a faster traversal from a single-child ( , )-node to its only H -child. This traversal costs amortized (log log ) time. The details and construction of shortcuts are described in Section 5.

Approximate Counters
Implementing the sampling operation in Lemma 3.1 reduces to being able to traverse from an ( , primary)-branching node to one of its ( , primary)-children , where the choice of an ( , primary)-child is random with probability that is approximately proportional to the number of -primary endpoints touching . The implementation of the random choice is supported by maintaining an approximate -counter at each ( , primary)-node. Notice that an H -node could be an ( , primary)-node for several , so there could be several approximate -counters maintained in an H -node. The advantages of using approximate -counters, as opposed to precise counters, are two-fold. First, each approximate -counter uses only (log log ) bits, and so (log /log log ) approximate -counters can be packed into a single machine word and be collectively manipulated in (1) time. Second, approximate counters can only take on (log ) (1) values, and hence a decrement-only counter can only generate (log ) (1) total work throughout its lifetime. The maintenance of approximate -counters and the sampling algorithm are explained in Section 6 and Section 7.4.

Shortcut Infrastructure
As described in Section 4.4, the purpose of shortcuts is to allow for e cient navigation between a single-child ( , )-node and its only ( , )-child . If the graph is static, a direct pointer between and could be stored in the data structure so that can be directly accessed from . The challenge is to maintain useful shortcuts in the midst of structural updates to H .

H-shortcuts. An H -shortcut
is a data structure connecting an ancestor to a descendant in H . H -shortcuts are only stored between a subset of eligible pairs of ancestordescendant pairs. The eligible pairs are determined as follows. For a positive integer , de ne its least signi cant bit index, denoted by LSBIndex( ), to be the minimum integer such that 2 divides but 2 +1 does not. For an H -node , let depth H ( ) be the distance from to the root of the tree in H that contains . The power of a pair of nodes and is de ned as The "+1" is included because LSBIndex is not well defined at zero.
In order for an H -shortcut to exist between and , any intermediate node on the path from to must have LSBIndex(depth H ( ) + 1) < P ( , ). If is the H -child of , then P ( , ) = 0 and is an eligible H -shortcut, which is called a fundamental H -shortcut.
The following lemma states that the set of H -shortcuts on an ancestor-descendant path do not cross each other.
Assume the claim is false, and so there exist two H -shortcuts 1 3 and 2 4 . By de nition this implies . Figure 5 illustrates C The H -shortcuts in C H ( , ) can be partitioned into two sequences: one with strictly increasing powers and one with strictly decreasing powers. To see this, notice that for any sequence of consecutive integers, there is a unique largest LSBIndex value among the sequence.
For any H -node let ( ) = LSBIndex(depth H ( ) + 1). Let * be the unique H -node on such that ( * ) > ( ) for all ∈ \{ * }. It is straightforward to see that no H -shortcut on crosses * and hence C Since the maximum depth is max = log , the largest possible power of an H -shortcut is log log ( , )-shortcuts. Let be a single-child ( , )-node and let be the ( , )-child of , which by de nition must be either an ( , )-branching node or an ( , )-leaf. The purpose of maintaining H -shortcuts is to allow one to quickly move from to . Ideally, the data structure will traverse the (log log ) H -shortcuts in C H ( , ). However, forcing all of the H -shortcuts in C H ( , ) to be maintained by the data structure seems to complicate the process of updating H -shortcuts as H changes. In particular, when an -witness edge { , } is deleted, H goes through several structural changes by merging an ancestor (or ) with a subset of the H -siblings of . 4 All H -shortcuts that were connected to (or ) and those H -siblings need to be updated at the same time. Since we are ne with (log log ) amortized time for the traversal, the process of updating shortcuts (due to changes in the hierarchy or the corresponding ( , )-forests) becomes simpler by allowing a weaker invariant governing which shortcuts are actually present. immediately return all the shortcuts back. Instead, the data structure partially recovers enough 5 shortcuts to maintain Invariant 5.3, and then employs a lazy approach in which shortcuts are only added (via a covering process) when they are needed. the set of ( , )-shortcuts between and is exactly C H ( , ). We use a potential argument to prove that the amortized cost of traversing from to is (log log ) time; see Section 9.2.
There are also certain cases where the structure of H does not change, but some ( , )forests do change (for example, whenever an H -leaf gains or loses an ( , )-status). To support structural changes in H or in ( , )-forests, the data structure will at times uncover an ( , )shortcut of power by removing and adding the two consecutive ( , )-shortcuts of power − 1 that were covered by . In order to accommodate an e cient uncovering operation, during a covering operation the data structure continues to store the covered H -shortcuts so that they are readily available when a subsequent uncover operation occurs. The H -shortcuts stored by the data structure that are strictly covered by some ( , )-shortcuts are called supporting Hshortcuts; these supporting shortcuts do not have ( , )-status. The H -shortcut is always 5 Notice that Invariant 5.3 implies that the shortcut data structure is not required to store all of Cover H ( , ) in order for the invariant to hold.
directly accessible from (the deeper node), but not necessarily from (the shallower node).
From the perspective of , is called an upward H -shortcut, while from the perspective of , is called a downward H -shortcut.
An upper bound on the number of H -shortcuts that need to be stored at each H -node is captured by the following straightforward corollary. ( Let be the path from ∈ H to its H -root. For each edge depth and type , at most one ( , )-shortcut is deviating from , and each such shortcut has at most (log log ) supporting shortcuts with exactly one endpoint on . (Recall that ( , )-shortcuts form paths from singlechild ( , )-nodes to their ( , )-child. Branching ( , )-nodes have no ( , )-shortcuts leading to descendants.) Thus, for each ( , ) pair, at most one fundamental ( , )-shortcut deviates from . All H -shortcuts connecting H -nodes on form a laminar set, and so there are at most 2 max = (log ) such H -shortcuts. Thus, the total number of stored shortcuts with one endpoint in is (log log log ), and the total number of distinct fundamental ( , )-shortcuts with one endpoint on is (log ).
In the rest of this section, we describe how H -shortcuts are stored.

The H-shortcut data structure
Information stored at H-nodes. Due to Corollary 5.4, every node in H has at most 3 max +1 = (log ) downward ( , )-shortcuts at any given time. Each node stores an array D of size at most 3 max + 1 storing all downward ( , )-shortcuts, together with a bitmap O indicating which array slots of D are in use. 6 The size of D is chosen to be exactly enough for storing pointers to ( , )-shortcuts for all possible ( , ) pairs as well as one additional slot for temporary use during promotions/upgrades. However, a single shortcut may be shared by many ( , ) pairs. In order to support fast access from to its downward ( , )-shortcut, Notice that for an H -node and a power , there is at most one upward H -shortcut from with power . Thus, each node maintains an array U of (log log ) pointers to shortcuts, sorted by power, to the upward supporting H -shortcuts of . Moreover, at each node the data structure stores a (3 max + 1)-length array U I of (log log log )-bit integers for each ( , ) ] points to an ( , )-shortcut entering , if such a shortcut exists.
Notice that each entry in the D I and U I arrays is represented with (log log ) bits, and there are (log ) ( , ) pairs. These entries are packed into (log log ) memory words so that the data structure is able to update the entire array e ciently via lookup tables in (log log ) time.
The following lemma summarizes how shortcuts are used to support various operations needed locally in one H -node. Given and a bitmap of length 3 max + 1, remove the ( , )-shortcut status from for all ( , ) pairs indicated by ( (min{| | + 1, log log })).
Given ∈ H and an ( , ) pair, return the ( , )-downward H -shortcut at or report that such a shortcut does not exist ( (1)).
Given ∈ H and an ( , ) pair, return the ( , )-upward H -shortcut at or report that such a shortcut does not exist ( (1)).

(Traversal and Covering) Assume Invariant 5.3 holds for all H -nodes with depth ≥ . Given
a single-child ( , )-node whose ( , )-child is , traverse from to via ( , )-shortcuts while guaranteeing that after the traversal is completed, the set of ( , )-shortcuts between and is exactly C then the data structure covers the two shortcuts with the H -shortcut having power + 1.
This is done as follows. Covering may create the opportunity to cover another shortcut of the next higher power. The data structure uses U to access the upwards shortcut with power + 1. If exists and is also an ( , )-shortcut then the data structure covers and with , and recursively looks to see if there are more shortcuts to cover at power + 2, and so on.
It is straightforward to verify that at the end of the traversal the set of ( , )-shortcuts connecting and is exactly C which is ( + log log ) where is the number of ( , )-shortcuts being covered during the traversal.
In Section 9.2 we show that by de ning the potential function to be the number of all ( , )-shortcuts that could be covered but are not yet covered, this operation has amortized cost (log log ) time. The shortcut infrastructure is very sensitive to the merge operation (e.g., Operation (2) in Lemma 3.1). In particular, when an -witness edge { , } is deleted, H goes through several structural changes by merging an ancestor of (or ) with a subset of its H -siblings. These merges require updating the shortcut infrastructure, which seems to be a very complicated task when supporting these types of changes. Speci cally, we need to employ a special strategy that ensures Invariant 5.3 holds after the entire Delete operation.

Maintaining Invariant 5.3 Through Structural Changes to H
In order to provide an e cient implementation, observe that during such a single deletion, all merged H -nodes (and their appropriate H -siblings) end up being on the paths between and and their respective H -roots. See Figure 7. Thus, we are able to employ the following strategy.
First, at the beginning of the delete operation, the algorithm completely uncovers and removes all H -shortcuts that touch H -nodes on the two paths. In particular, by Lemma 5.5, the algorithm removes (1) (log ) fundamental shortcuts, (2) (log ) shortcuts with both endpoints on the path, and (3) (log log ) deviating shortcuts from each path for each ( , ) pair. Recall that deviating shortcuts have one endpoint on the H -path in question.
After removing these H -shortcuts, Invariant 5.3 no longer holds for pairs of H -nodes where at least one node is on the a ected paths. However, these are shortcuts with ( , )-status for some < , and so during the deletion operation at depth we never use such shortcuts.
Hence, removing them does not a ect the other operations that take place during the edge deletion process at depth . Lemma 5.9 summarizes the operations that remove and restore shortcuts along paths in H , which are used to guarantee that Invariant 5.3 holds after the deletion operation terminates. Since the implementation requires interaction with the local trees, we defer its proof to Section 9.1. L E M M A 5 . 9. The data structure supports the following operations on H with amortized time cost (in parenthesis). Given an H -node : Uncover and remove every H -shortcut that is touching any node that is an ancestor of ( (log (log log ) 2 )).
Given , its H -parent , and a bitmap , add a fundamental H -shortcut for all ( , ) pairs indicated by ( (log log )).
Add all fundamental H -shortcuts between consecutive ancestors of that are ( , )-shortcuts for at least one ( , ) pair ( (log log log )).

Implementation of Approximate Counters
In this section, we describe how approximate -counters are implemented. Without loss of generality we assume that the input graph is simple. Hence, all approximate -counters are only required to represent a (1 + (1))-approximation of integers in the range [0, 2 ].

Approximate Counters
Each ( , primary)-leaf maintains the exact number of ( , primary)-endpoints touching . The precise number of ( , primary)-endpoints in a subtree of any ( , primary)-node could be computed exactly using a formula tree de ned by the induced ( , primary)-tree rooted at where the value at each vertex is the sum of the values of its children. (Because the local trees are binary, the induced tree is also binary, and has height (log log log ).) If one were to use such a strategy, then every H -node has the potential of storing (log ) counters, where each counter uses (log ) bits, for a total of (log ) words. Thus, splitting and merging vertices may cost Θ(log ) time each, which is too expensive for our purposes.
Instead, the data structure e ciently maintains approximate -counters for nodes in H with a multiplicative approximation guarantee of (1 + (1)) using only (log log ) bits per approximate -counter.
The structure of an approximate counter. Let  Given an H -node and a depth , update/return the approximate -counter stored at ( (1)).
Given the oating point representation of an approximate counter, return its integer representation ( (1)).
Given the integer representation of an approximate counter, return its oating point representation ( (1)).
Given two arrays of (log ) approximate counters packed into (log log ) words, return their coordinate-wise sum, packed into (log log ) words ( (log log )). Update the approximate counters to re ect a change in the number of ( , primary)-endpoints at a given H -leaf ( (log (log log ) 2 )).
Given an ( , primary)-tree T rooted at , rebuild approximate -counters for all ( , primary)nodes in T to restore Invariant 6.3 for those nodes ( (|T |(log log ) 2 )).
When merging two sibling H -nodes, compute the approximate -counters for all ∈ [1, max ] at the merged node ( (log log )).
When splitting an H -node into two sibling H -nodes, compute the approximate -counters for all ∈ [1, max ] at the two sibling nodes ( (log log )).
The proof of Lemma 6.5 depends on the implementation of local trees, which we provide in Section 7. Thus, the proof of Lemma 6.5 is deferred to Section 8.3.

Local Trees
The purpose of the local tree L ( ) is to connect an H -node with its H -children while supporting various operations. A local tree is composed of a three-layer binary tree and a special binary tree called the bu er tree. The three-layer binary tree is composed of a top layer, a middle layer and a bottom layer. See Figure 8 for an illustration. The top tree 7 is a mergeable, (log log )-height tree whose leaves are middle tree roots.
Its purpose is merely to gather up all middle trees within a single tree, while increasing the overall height of the local tree by only (log log ).
Local tree roots and local tree leaves. The root of L ( ) has two children: the root of the bu er tree and the root of the top tree. The root of L ( ) also has a pointer pointing to in H .
When a new H -node ∈ H is created, L ( ) is initially empty.
H-node representatives. Each H -child of is not in L ( ) as such, but is present through a representative , which is a leaf in L ( ). We distinguish from because they have di erent characteristics and store di erent information.
The local tree leaf stores a pointer to ∈ H , the weight of , a parent pointer, approxi- Not to be confused with the top tree dynamic tree data structure of Alstrup, Holm, Lichtenberg, and Thorup [4]. 8 Notice that if is an ( , )-branching node but is not, then ∈ H has ( , )-status but ∈ L ( ) does not have local ( , )-status. This is the main reason for notationally distinguishing from . Detach a bu er/bottom tree leaf ( ((log log ) 2 )).
Given an edge depth ∈ [1, max ], a bu er/bottom leaf , and a value , decrease the approximate -counter at to ( (log log )).

In addition, the bu er tree supports the following operations:
Attach a bu er tree leaf ( ((log log ) 2 )).

Convert the bu er tree to a bottom tree ( (1)).
Given an edge depth ∈ [1, max ], a bu er leaf , and a value , set the approximate -counter at to be ( (log log )).

P R O O F . A bu er tree is implemented by an o -the-shelf mergeable binary tree with
(log log ) worst case time for each attach, detach, and merge operation. 9 However, in order to support updates to the vector of approximate counters, an (log log ) factor overhead is applied to each of the operations. See Lemma 6.4. Hence the worst case time cost for each operation is ((log log ) 2 ). From these three operations, bottom trees are only subject to detach.
Since we only require the height of a bottom tree to be (log log ), no rebalancing is necessary after detaching a leaf. In order to obtain correct rank( ), each attach, detach, and merge also updates the weight of the given bu er/bottom tree root.
To add ( , )-status to a bu er tree leaf , the data structure traverses up the bu er tree and sets the ( , )-bit to 1 in all ancestors of in the bu er tree. To remove ( , )-status from a bu er/bottom leaf , the data structure updates the ( , )-bits at each ancestor of . If a leaf has local ( , primary) status, it carries an approximate -counter. Such counters can be increased or decreased in (log log ) time by updating all ancestors of in its bu er/bottom tree.

R E M A R K 7. 2.
Observe that only the bu er tree can acquire new leaves, and only bu er tree nodes can gain local ( , )-status and increase their approximate -counters. In particular, this implies that when a bottom tree leaf has to acquire a local ( , )-status, the algorithm removes the leaf from the bottom tree, updates its status and re-inserts the leaf into the bu er tree.

Middle Trees
All bottom tree roots are middle tree leaves. Middle trees respond to three types of updates at their leaves: a leaf losing ( , )-status, decreasing its approximate -counter, or decreasing its weight. Middle trees are maintained as weight-balanced binary trees satisfying Invariant 7.3.

I N VA R I A N T 7. 3. If is a middle tree leaf/bottom tree root it maintains ( ) and rank( ) = log ( ) . If is an internal middle tree node it maintains only rank( ), and if has children
, then rank( ) = rank( ) = rank( ) − 1.
The operations described in Lemma 7.5 speci cally maintain Invariant 7.3. As a consequence of Invariant 7.3, the path from any middle tree leaf (bottom tree root) to the corresponding middle tree root has length log( ( ) ( ) ) + (1). This property is used to bound the number of local tree nodes traversed when walking from any H -node to its H -parent via the local tree L ( ). In accordance with Invariant 7.3, two middle tree roots with the same rank may join, and become children of a new middle node parent.
Local Shortcuts. Each of the middle trees maintains a local shortcut infrastructure in much the same way that shortcuts are maintained in H . Let and be two nodes in the same middle tree such that is a proper ancestor of . Then is an eligible local shortcut if and only if 9 Note that all such off-the-shelf data structures are, in fact, binary search trees, but we do not impose any total order on the leaves, nor do we require any operation analogous to binary search.
Notice that the H -shortcuts are de ned from the depths of H -nodes which increase along the path from an H -root to an H -leaf. In contrast, in middle trees the ranks of middle tree nodes decrease on the path from a middle tree root to a middle tree leaf. The de nition of power is symmetric between and , so the increasing/decreasing direction here does not matter. Local Reduce the weight of a middle tree leaf ( (log log log )).
Given an edge depth ∈ [1, max ] and a middle tree leaf , update the approximate -counter at ( (log )).

Given a newly created bottom tree root, create a new middle tree leaf ( (1)).
Join two middle trees with the same rank ( (log log )).

P R O O F . We address each operation in turn.
Reducing ranks. When the weight of a middle tree leaf is reduced (because its bottom tree su ered enough leaf deletions) it may cause a discrete reduction in its rank, which violates Invariant 7.3. If so, we destroy all middle tree nodes that are strict ancestors of . We rst uncover all local shortcuts touching the path from to its middle tree root . This procedure is the same as the uncovering procedure described in Section 9.1. In order to avoid redundancy, Update an approximate -counter. If the approximate -counter at changes it invalidates the approximate -counters at all ancestors on the path from to its middle tree root . Each can be updated in (1) time (Lemma 6.4), for a total of (log ) time.
Create a new middle tree leaf. The bu er tree root maintains its weight and approximate -counters. Thus, when the bu er is converted to a bottom tree, its root (the new middle tree leaf) can be inserted into the middle tree collection in (1) time. (As a new middle tree root, it is also inserted as a leaf in the top tree; this is accounted for in Lemma 7.6.) Joining middle trees. To join roots , , we create a new middle tree parent and compute its approximate -counters in (log log ) time (Lemma 6.4) by adding the vectors at , . We set the bitmap of to be the bitwise OR of bitmaps stored in and . In order to maintain Invariant 7.4, the data structure adds trivial ( , )-shortcuts whenever has an ( , )-bit set to 1 and exactly one of or has its ( , )-bit set to 1. This is done in (1) time using bitwise operations.

Top Trees
The top tree is an (log log )-height mergeable binary tree. All middle tree roots are top tree leaves. As a consequence of the middle tree reduction procedure described below, each top tree has at most 4 log top tree leaves. Each top tree node maintains pointers to its parent and children, approximate counters, and a bitmap of ( , ) pairs indicating whether a local tree leaf with ( , )-status appears in the subtree of .
Whenever we invoke the Middle Tree Reduction procedure, the entire top tree is rebuilt.
Middle Tree Reduction. There are at most log possible ranks for a middle tree node. If there are at least 2 log middle trees in a local tree, then the data structure invokes the middle tree reduction procedure: (1) destroy the top tree, (2) repeatedly take two middle tree roots with the same rank, and join the corresponding middle trees, then (3)  Insert a middle tree root into the top tree ( ((log log ) 2 )).
Remove a middle tree root from the top tree ( ((log log ) 2 )).
Merge the top trees of two local trees ( ((log log ) 2 )).
Given the list of all middle tree roots that are leaves of the top tree, perform a middle tree reduction and rebuild the top tree ( (log log log )).
Update approximate counters along the path from the given top tree leaf to the top tree root ( ((log log ) 2 )).

Maintaining Precision when Sampling
Recall from Invariant 6.3 that ( ) was de ned as the maximum possible height of any arithmetic formula tree (summing up approximate counters) with ∈ˆat the root. We de ne a similar function for nodes inside local trees. If ∈ L ( ), de ne ( ) as: where ℎ bot/top ( ) = (log log ) is precisely the maximum number of top, bottom, and bu er trees nodes on a path from to a leaf of L ( ). With this de nition, it is straightforward to see that when , are the children of , that ( ) = max( ( ), ( )) + 1.
We rst prove that all nodes in a local tree have the correct precision in terms of ( ).

Maintaining Invariant 6.3. Invariant 6.3 constrains the accuracy of approximate -counters
in terms of (·). We prove that Invariant 6.3 is maintained, by analyzing the accuracy of approximate -counters inside the local trees in terms of (·).
Fix an edge depth and a local ( , primary)-branching node ∈ H . Assume, inductively, that every local ( , primary)-leaf in L ( ) representing the ( , primary)-child of satis es Invariant 6.3 andˆ( ) =ˆ( ). We now prove that Invariant 6.3 is satis ed at as well.

Sample an ( , primary)-child
This section shows that an ( , primary)-child can be e ciently sampled approximately proportional to its approximate -counter. The data structure begins at the root of L ( −1 ), which is a local ( , primary) node, and walks down to a descendant leaf in L ( −1 ) as follows. If we are at a local ( , primary)-branching node , let and be its local ( , primary)-children. We randomly choose a child with probability proportional toˆ( ) andˆ( ), respectively, and navigate downward using local ( , primary)-shortcuts to nd the next local ( , primary)-branching child. The process terminates when we reach a local leaf (representing ) with local ( , primary)-status.
Let 0 be the root of L ( −1 ), and the sequence 1 , 2 , . . . , be all local ( , primary)branching nodes which are on the path between 0 and +1 = . For all ∈ [0, ], let and be the two local ( , primary)-children of , with being the ancestor of +1 . 10 Then we have for all ∈ [0, ],ˆ( ) =ˆ( +1 ), and the probability that a particular ( , primary)-child 10 In the case of = 0, if the root is not a local ( , primary)-branching node then we takeˆ( 0 ) to be zero.
is sampled is at most or decide if has a unique ( , )-child ( (log log )).

Local Tree Operations
Given an H -node and a bit vector , add local ( , )-status to the local tree leaf for all ( , ) pairs indicated by ( ((log log ) 2 )).
Given an H -node and a bit vector , delete local ( , )-status to the local tree leaf for all ( , ) pairs indicated by ( (log log )).
Given an ( , primary)-branching node , sample an ( , primary)-child with probability at mostˆ( To test whether there is a unique leaf with ( , )-status, we navigate downward from the root of L ( ), following local ( , )-shortcuts until reaching either a local ( , )-leaf (necessarily unique) or a local ( , )-branching node (indicating non-uniqueness). We then cover local ( , )-shortcuts on the path from to as long as it is possible. As shown below, the amortized cost of this operation is (log log ). Amortized Cost Analysis. We use a credit system. Every bu er tree leaf carries Θ(1) credits and every middle tree root carries Θ(log log ) credits. Suppose the bu er tree matures and becomes a bottom tree, say with root . At this moment the tree has Θ(log ) credits, which will pay for all future costs associated with updating the middle and top tree ancestors of .
The following three types of events change the information stored at .
1. changes rank. Since the bottom tree is only subject to detach operations (see Remark 7.2), its weight is non-increasing. Therefore, this happens at most log times.
3. 's approximate -counter changes. The approximate counters are non-increasing, and each such counter can take on (log +1 ) di erent values (Section 6). Since there are log possible values for , the total number of counter changes is (log +2 ).
Each of the above events requires that we update or delete the entire path form to the local tree root, which can have length Θ(log ). Events of type (1) take (log log log ) time to destroy the path and reinsert new middle tree roots into the top tree, each with (log log ) credits. Events of type (2) and (3) take (log ) time to update the ( , )-status or approximate -counters of all ancestors of . Since = 2, the total cost for events of type (3) is the bottleneck.
They take (log +3 ) time over the life of the bottom tree. We set ≥ + 3 = 5, so the credits of a bottom tree su ce to pay for all costs incurred over the lifetime of the bottom tree.
A middle tree reduction procedure is invoked if the leaf set of the top tree has size | | ≥ 2 log . Thus, it begins with at least 2 log · (log log ) credits and ends with at most log · (log log ) credits, which pays for rebuilding the top tree in (log log log ) time (Lemma 7.6).
The number of shortcuts removed is bounded by the number created, so it su ces to account for the cost of creating shortcuts. Local shortcuts are created in two ways: (i) in response to the creation of a middle tree node (joining two middle trees), and (ii) lazy covering. The cost of case (i) is ultimately paid for by the deletion of that middle tree node, which in turn is paid for by the bottom tree that triggered the deletion. The cost of case (ii) is attributed to the removal of ( , )-status at some corresponding middle tree leaf with an ( , )-status, which is accounted for in the cost of type (2) events.

Loose Ends
Some of the operations on the hierarchy H required the de nition of ( , )-forests (Section 5) and local trees (Section 7) and could not be described until now. In Section 8.1 we analyze the cost of searching for a replacement edge using the two-stage batch sampling test sketched in

The Batch Sampling Test
Recall from the deletion algorithm of Section 3.2.1 that u i is the new H -node resulting from merging a set of siblings. In this section we show how the data structure performs the batch sampling test among -primary endpoints touching u i . Let and be the number of -primary and -secondary endpoints touching u i , and letˆ=ˆ(u i ) be a (1 + (1))-approximation of .
(Retrievingˆis Operation (9) from Lemma 3.1.) Single Sample Test. To (1 + (1))-uniformly sample one -primary endpoint touching u i , the data structure sets = u i and iteratively performs the following step. Base case: If is an ( , primary)-leaf, then return an -primary endpoint at uniformly at random. General case: If is an ( , primary)-branching node, then use L ( ) to sample an ( , primary)-child of with probability at mostˆ( . If is an ( , primary)-branching node or leaf, we set = and repeat. Otherwise, we repeatedly follow the ( , primary)-shortcuts leaving to its ( , primary)-child , set = , and repeat (Lemma 5.7).
Notice that with accurate counters this procedure picks a perfectly uniformly random -primary endpoint. Let , { , } be the sampled endpoint and 0 = u i , 1 , . . . , = be the sequence of ( , primary)-branching nodes on the path in H from u i to . Then the probability .
The 1/ ( ) factor re ects the fact that once we reach the H -leaf , an endpoint touching is selected (exactly) uniformly at random, without any approximation. To check whether { , } is a replacement edge or not, it su ces to check whether = u i . This can be accomplished by starting from and repeatedly accessing the H -parent until is reached. Using local trees, the cost of computing H -parents along a path telescopes to ( ) = (log log log ).
The Preprocessing Method. Another way to sample -primary endpoints is to rst enumerate all -primary endpoints and all -secondary endpoints touching u i in (( + ) log log ) time, mark all enumerated endpoints and store all -primary endpoints in an array. Then the data structure samples an -primary endpoint uniformly at random from all enumerated -primary endpoints and checks whether the other endpoint is marked in (1) time.
Batch Sampling Test on Samples. The data structure runs the two sampling methods in parallel and halts when the rst nishes. Thus, the time to sample ( , primary)-endpoints is min ( + ) log log + , log log log .

Cost Analysis for Sampling Procedure
As described in Section 3.2.2, the sampling procedure either returns a replacement edge, or invokes the enumeration procedure. Roughly speaking, if no replacement edge is found, the cost is charged to either upgrades of ( , secondary) endpoints or promotions to ( , primary) endpoints. If any replacement edge is found, the data structure is willing to pay (log (log log ) 2 ) cost because this happens at most once per Delete operation.
If the enumeration procedure is invoked, the data structure upgrades all enumerated -secondary endpoints touching u i to -primary endpoints, and then all -primary endpoints touching u i associated with non-replacement edges are promoted to ( + 1)-secondary endpoints.
Let be the fraction of -primary endpoints touching u i associated with replacement edges before the execution of the sampling procedure. The rest of the analysis is separated into two cases: Case 1. If ≥ 3/4, the probability that the rst batch sampling test returns with a replacement edge is at least 1 − (1/4 + (1)) (log log ) > 1 − 1/log . 11 The second batch sampling test, if invoked, returns a replacement edge if at least half the (log ) endpoints sampled belong to replacement edges. By a standard Cherno bound, the probability that the second batch fails to return a replacement edge and halt is exp(−Ω(log )) < 1/ .
The expected time cost is therefore We charge the Delete operation (log (log log ) 2 ), which covers the expected cost of the two batch sampling steps and the expected cost of dealing with primary endpoints if the enumeration step is reached. If the enumeration step is reached, endpoint upgrades pay for the Θ( (log log ) 2 ) cost of dealing with secondary endpoints.
Case 2. Otherwise, < 3/4. If the enumeration procedure is ultimately invoked, a 1 − = Ω (1) fraction of the -primary endpoints touching u i belong to non-replacement edges, which are promoted to depth + 1, and all -secondary endpoints are upgraded to either -primary or ( + 1)-secondary status. In this case the time cost is which is charged to the promoted edges/upgraded endpoints. We need to prove that the probability of terminating after the second batch sampling test is su ciently small. If ≥ 1/4 then the probability of the rst batch sampling test not returning a replacement edge is at most (3/4 + (1)) (log log ) < 1/log . In this case the expected cost is If < 1/4 then, by a Cherno bound, the probability that at least half the sampled endpoints belong to replacement edges is exp(−Ω(log )) < 1/ . Therefore the expected cost when the enumeration procedure is not invoked with < 1/4 is at most which is charged to the Delete operation. Given an H -leaf and an ( , ) pair, designate an ( , )-leaf (log (log log ) 2 ) .
Given an ( , )-tree T rooted at , an integer ∈ [ , max ], an endpoint type , and two subsets of ( , )-leaves − and + (these subsets need not be disjoint), update H so that all of the leaves in − lose their ( , )-leaf status, and all leaves in + gain ( , )-leaf status (if they did not have it before) (|T |(log log ) 2 + 1) . Notice that this operation is equivalent to rst performing the lazy covering on the ( , )shortcuts from to its ( , )-parent and then removing . Hence, the time cost for removing ( , )-status from is amortized ((log log ) 2 ). We can remove ( , )-status from a group of leaves − in (| − |(log log ) 2 ) amortized time by repeating this procedure for every leaf. Notice that Invariant 5.3 holds for all H -nodes with depth ≥ because fundamental ( , )-shortcuts are covered when H -nodes lose their ( , )-branching status.

Each operation assumes that
Enumerating ( , )-children. This is an operation of Lemma 7.8.
Given an ( , )-tree T and a set of leaves + in T, add ( , )-status to the leaves in + .
First of all, the data structure creates a "dummy" tree induced from the set of leaves + and the root of T , by rst copying the entire ( , )-tree T , enumerating all its leaves and removing all the leaves that do not belong to + . 12 Hence, without loss of generality, we now assume + is the entire leaf set of T and that there are no potential shortcuts w.r.t. T .
Notice that, after adding ( , )-status to the leaves in T , every ( , )-branching node of depth at least in T is also an ( , )-branching node. Moreover, for each such ( , )-branching node, adding ( , )-status to the node converts at most one H -node into a new ( , )-branching node.
De ne T * to be the subtree of H induced by all ancestors of leaves in T up to depth . Our rst task is to enumerate all nodes of T * at depth ; call them 1 , . . . , . and has depth strictly greater than we iteratively uncover the downward shortcut from until it is , where has depth at most , and move the locus of the search to . If nodes are output by this procedure, the number of shortcuts followed/uncovered is · (log log ).
Let T 1 , . . . , T be the subtrees of T rooted at 1 , . . . , and let W 1 , . . . , W be the ( , )-trees rooted at these nodes. It may be that some does not currently have ( , )-status, in which case W is empty. In this case we simply traverse T, giving each node encountered ( , )-status.
In Claim 8.3 we focus on the non-trivial problem of merging (T, W ) when is an existing ( , )-root. Here "W -status" is synonymous with ( , )-status. 12 This is the reason for having 3 max +1 slots in the Down arrays; the +1 is for creating a temporary dummy tree of this type. Case 1a: is a branching T-node but not a branching W -node. After the merging process will become a branching W -node, and therefore can have no downward W -shortcut. We repeatedly uncover the W -shortcut leaving . In the nal step we uncover a fundamental shortcut , give local W -status in L ( ), and then designate a branching W -node. This reduces the situation to Case 1b. Case 2b: is a single-child T-node, but its T-child is neither a W -node nor has a W -shortcut.
In this case, will become a branching W -node or W -leaf. In addition, there may be a new branching W -node on the path from to . We proceed to nd the new branching node as follows. Initialize = and let refer to its current downward T-shortcut. Whenever is a W -node or has a W -shortcut, we move the locus of the search to , setting = . Whenever has a downward T-shortcut and a W -shortcut with ≠ , we uncover the one with maximum power, or uncover both if they have the same power. (|T| log log ). The running time is dominated by the cost of introducing up to (|T|) new branching vertices and adding W -status to (|T|) nodes. The cost of adding W -status is ((log log ) 2 ) and the cost of uncovering a fundamental W -shortcut, in Case 1a or Case 2b, is also ((log log ) 2 ). In total the time is (|T|(log log ) 2 ).

Approximate Counters Operations -Proof of Lemma 6.5
Update ancestor approximate -counters. The data structure updates the approximate -counters from a given H -leaf to the corresponding H -root. Let be the current ( , primary)node. If is a single-child ( , primary)-node, then it adopts the approximate -counter of its ( , primary)-child. If is the child of an ( , primary)-branching node , the data structure updates the approximate -counters of from L ( ) using Lemma 7.8. At this point adopts the approximate -counter of the root of L ( ). There are at most log branching nodes on the path and each costs ((log log ) 2 ) time to update an -counter (Lemma 7.8), for a total of (log (log log ) 2 ) time.
Update approximate -counters in an ( , primary)-tree T rooted at . At the beginning of this operation, the approximate -counters at all ( , primary)-leaves are accurate but those at internal nodes are presumed invalid. Beginning at the root , the data structure traverses the ( , primary) tree T in a postorder fashion, setting approximate -counters in this order. As in the analysis above, the cost is ((log log ) 2 ) per node in T , for a total of (|T |(log log ) 2 ).
Update approximate counters at a merged/split H-node . Suppose = u i is the result of merging several siblings. We inspect the root of L ( ) and retrieve the bitmap indicating for which ( , primary)-pairs is an ( , primary)-branching node. Using table lookups, in (log log ) time we make an (log log log )-bit mask and copy all the approximate -counters from the root of L ( ) to . The case when is the result of a split is handled in the same way.

Amortized Analysis of Shortcut Maintenance
In this section, we describe how shortcuts are utilized and supported on H . Moreover, we provide a potential function for H -shortcuts that contributes to the amortized analysis for the Delete operation.

Covering All Shortcuts Touching Specified Paths -Proof of Lemma 5.9
The remainder of this section constitutes a proof of Lemma 5.9. Let be a path from the given H -node to the corresponding H -root 0 .
Uncover and remove all H-shortcuts touching . Removing a fundamental shortcut is a local tree operation that costs ((log log ) 2 ) time. Uncovering a shortcut with both endpoints on the path costs (log log ) time by Lemma 5.6. (Such a shortcut may be an ( , )-shortcut for multiple ( , ) pairs.) Uncovering a non-fundamental deviating ( , )-shortcut costs (1) time, by setting the appropriate ( , )-bits in the supporting shortcuts. Thus, the total cost of uncovering and removing all of the H -shortcuts on the a ected paths is (log (log log ) 2 ).
For each H -node iterated from 0 to , the data structure rst enumerates all downward H -shortcuts in D . Then the data structure repeatedly uncovers the H -shortcut with the largest power > 0 until every H -shortcut leaving is fundamental.
The data structure then uncovers each fundamental H -shortcut leaving by the following procedure. To uncover (remove) a fundamental H -shortcut , the data structure rst detaches the local leaf in L ( ) representing and re-inserts into the bu er tree. Notice that this operation does not alter the structure of H , so any H -shortcut leaving is not a ected.
Then the data structure adds local ( , )-status to for all ( , ) pairs indicated in the bitmap . This enables one to navigate from the root of L ( ) to via local ( , )-shortcuts in L ( ).  It is straightforward to see that, after log log passes, if there is any ( , )-shortcut with at least one endpoint on the path that could be covered, the other endpoint must be outside of the path and hence is a deviating ( , )-shortcut. Since there are a total of ( max ) = (log ) non-fundamental H -shortcuts to consider, the total time cost is (log log log ).

Shortcut Cost Analysis
At rst glance it seems sensible to charge the cost of deleting a shortcut to the creation of the shortcut, and therefore only account for their creation in the amortized analysis. This does not quite work because shortcuts are shared between many ( , ) pairs and the cost of deleting a shortcut depends on how broadly it is shared. The amortized analysis for H -shortcuts focusses on supporting potential shortcuts de ned as follows: Consider a supporting potential shortcut (which may or may not be stored) and de ne to be the number of ( , ) pairs for which is covered by a maximal potential ( , )-shortcut but is not covered by a stored ( , )-shortcut. 13 De ne a function as follows.
is not a fundamental shortcut, 0, if is a fundamental shortcut.
Let be the set of all shortcuts de ned over H , st be the set of all stored non-fundamental shortcuts, and f be the set of all stored fundamental shortcuts. The potential Φ is de ned as 13 The count also takes the dummy tree into account, as if it had a special ( , )-status. Notice that the dummy tree only exists in the middle of the Delete operation; see Section 8.2. follows.
Uncovering a fundamental shortcut could possibly cause a detach-reattach operation in the local tree, which costs ((log log ) 2 ) time; see the proof of Lemma 5.9 in Section 9.1. This is the reason that we give more credit to a stored fundamental shortcut than to a non-fundamental shortcut. Throughout the algorithm execution, there are many places where the ( , )-forests are modi ed. These structural changes a ect the potential Φ so we list them in the following paragraphs.
Adding ( , )-status to an H-leaf. (Lemma 8.1) Adding ( , )-status to an H -leaf increases Φ by (log (log log ) 2 ) since all new shortcuts that need to be created lie on the path from the leaf to its ( , )-parent. In particular, each of the (log ) new fundamental shortcuts increases Φ 3 by (log log ) 2 each, and both Φ 1 and Φ 2 increase by at most (log log log ) each.
Removing ( , )-status from an H-leaf. (Lemma 8.1) Removing ( , )-status from a leaf increases Φ by ((log log ) 2 ). Let be the ( , )-parent of . If loses its ( , )-status and its H -parent is no longer an ( , )-branching node, we will create one new fundamental shortcut from to a sibling of , increasing Φ 3 by (log log ) 2 . All new supporting potential ( , )-shortcuts will cover and have distinct powers. Thus, the net increase of Φ 1 will be at most (log log + 1) log log . Φ 2 is unchanged.
Creating a dummy tree. (Lemma 8.1) Create a dummy tree T by copying a maximally covered ( , )-tree. Recall that there are 3 max + 1 shortcut forests, one for every ( , )-pair and 1 for the dummy forest; we will say its shortcuts have ⊥-status. After creating the dummy tree T and giving its maximal shortcuts ⊥-status, there is no change to Φ. Every potential ⊥-shortcut is a stored shortcut, and was formerly stored before T was created.
Removing ( , )-status from a subset of H-leaves. (Lemma 8.1) The data structure removes ( , )-status (or ⊥-status) from a subset of leaves in an ( , )-tree T (or dummy tree T ).
There are (|T |) leaves removed, and each removal increases Φ by at most ((log log ) 2 ), for a total of (|T |(log log ) 2 ).
Merging and destroying dummy trees. (Lemma 8.1) The data structure merges a maximally covered dummy tree T into an ( , )-tree, and destroys T . Observe that in the process of merging these trees, the ( , )-tree acquires new branching nodes and the set of supporting potential ( , )-shortcuts only loses elements. Thus Φ 1 does not increase. Every shortcut sup-porting the merged tree was in at least one of the two original trees before the operation, so Φ 2 and Φ 3 are also non-increasing. Fortunately, after the deletion operation most of these H -shortcuts are covered back. As mentioned in Section 5.2, after a deletion the data structure covers every possible supporting potential ( , )-shortcut with both endpoints at ancestors of or , as well as all necessary fundamental H -shortcuts with at least one endpoint ancestral to or . We claim that after covering back all necessary H -shortcuts on the two paths, the increase of Φ is upper bounded by (log (log log ) 2 ). Counting multiplicity, there are (log log log ) non-fundamental deviating shortcuts that the lazy covering method failed to restore after the Delete operation. Each contributes log log + 1 to Φ 1 , for a total of (log (log log ) 2 ). The number of non-fundamental shortcuts with both endpoints at ancestors of or is (log ), and each contributes log log to Φ 2 , for a total of (log log log ). Similarly, the (log ) fundamental shortcuts each contribute (log log ) 2 to Φ 3 , for a total of (log (log log ) 2 ). The increase in Φ due to these changes are charged to the Delete operation.

Main Operations -Proof of Lemma 3.1
We review how each of the 10 operations of Lemma 3.1 can be implemented in the stated amortized running time.
Operation (1) -Add or remove an edge with depth and endpoint type . The data structure rst adds (or removes) the given edge to the H -leaf data structures of its endpoints; see Section 4.1. If the addition/removal changes the ( , )-status of either endpoint, we update them with Lemma 8.1 and if = primary we update the approximate -counters using Lemma 6.5.
The time cost is (log (log log ) 2 ). endpoints touching u i , including the ones that are not promoted. Since |T | ≤ we have that this operation costs ( (log log ) 2 + 1) time.

Proof of Theorem 1.1
The correctness of the data structure follows from Section 3.2's maintenance of Invariant 2.2, using Lemma 3.1 to maintain H and Theorem 2.1 to maintain the witness forest F . In this section we prove that the amortized time complexity is (log (log log ) 2 ) per Insert or Delete and (log /log log log ) per Conn? query. Call H the data structure for H described in Lemma 3.1 and F the data structure for F from Theorem 2.1, xing ( ) = (log log ) 2 .

Insertion
To execute Insert( , ), the algorithm makes a connectivity query to F in (log /log ( )) = (log /log log log ) time. Then, there are two cases: If and are already connected, then the algorithm invokes Operation (1)  The algorithm also inserts { , } into F , in (log · ( )) = (log (log log ) 2 ) time.

Deletion
To execute a Delete( , ) operation, where = { , }, the algorithm rst removes from H through Operation (1), taking amortized (log (log log ) 2 ) time. If is a non-witness edge, then the operation is done. Otherwise, the algorithm also removes from F in (log · ( )) time.
Preparing Iterations. As mentioned in Section 5.2, before the iterations begin, all ancestors of −1 = −1 are found and stored in a list, using Operation (8). The cost of Operation (8) telescopes to (log log log ) time. In addition, all stored H -shortcuts touching the path from −1 to 0 are uncovered, using Lemma 5.9. We note that Invariant 5.3 now holds only for all H -nodes at depth ≥ , which validates all operations whose implementation depends on Lemma 8.1. Once the shortcuts have been removed, the iterations begin.
Establishing Two Components. On the iteration concerning depth , the algorithm runs two parallel searches starting from and , obtaining the connected components and .
Throughout the search, H -siblings of and are found via -witness edges enumerated by Operation (7). Let be the set of H -siblings in the same component with and be the of H -siblings for with . Notice that there are exactly | | − 1 and | | − 1 -witness edges in and respectively, and each -witness edge contributes 2 endpoints throughout the search.
Thus, the searches in parallel take amortized (min{| | −1, | | −1}(log log ) +1) time until the rst completes. At this point we can deduce which of or is the smaller weight component; suppose it is .
The algorithm uncovers and removes all remaining downward shortcuts on the siblings of that form (Lemma 5.9), then performs Operation (2) to promote all ( , witness)-edges in to ( + 1, witness) edges, with a negative amortized cost of −Ω((| | − 1) (log log ) 2 ), which pays for the cost of the two searches.
In conclusion, establishing two components costs amortized constant time.
Finding a Replacement Edge. Recall from Section 8.1 that is the fraction of -primary endpoints belonging to replacement edges and and are the number of primary and secondary endpoints. When > 3/4 the search for a replacement edge halts after the rst or second batch sampling test with probability 1 − 1/ , and costs (log (log log ) 2 ) in expectation, which is charged to the Delete operation. Suppose that the enumeration procedure is invoked, which upgrades all ( , secondary) endpoints to ( , primary) status (Operation (3)), and then some of the ( , primary) endpoints to ( + 1, secondary) status (Operation (4)). This procedure costs (( + ) log log ) time. The amortized time cost of Operation (3)  = log log 2 1 + 0 − 1 (12(1 − ) − 1) + 1 − 0 + 1 When < 3/4, the contribution of original primary endpoints ( ) is at most (1 + 0 − 2 1 )(log log ) 2 , which is at most 0 when 1 ≥ (1 + 0 )/2. When > 3/4 the enumeration procedure is invoked with probability at most 1/ , and the expected time cost is ((log log ) 2 ).
In conclusion, successfully nding a replacement edge in the rst or second batch sampling test costs (log (log log ) 2 ) expected time, which is charged to the Delete operation. If the enumeration procedure is invoked, then the search for a replacement edge may fail to nd a replacement edge at level . The amortized expected cost of the enumeration procedure at depth is ((log log ) 2 ), which is charged to the Delete operation.
Preparation for Next Iteration. If no replacement edge is found at the current depth , the algorithm splits −1 into to H -siblings u i−1 and v i−1 , through Operation (6). The split operation costs amortized ((log log ) 2 ) time. After the split, the algorithm restores all necessary downward shortcuts touching u i−1 , v i−1 , , or u i , as described in Section 5.2 and Lemma 5.9.
The covering of fundamental shortcuts ensures Invariant 5.3 to hold for all H -nodes at depth ≥ − 1. By the same argument from Lemma 5.9, the total cost of covering these shortcuts is (log (log log ) 2 ), which is charged to the Delete operation.
The End of Iteration. Suppose we nd a replacement edge at depth . The algorithm ends by restoring all necessary shortcuts with one endpoint at an ancestor of or . By Lemma 5.9, this costs (log (log log ) 2 ) time. Furthermore, this restores Invariant 5.3 holds for all nodes in H .

Combining the Costs.
Summing all costs, the total amortized expected time for an edge deletion is (log (log log ) 2 ).

Conclusion
We have shown that the Las Vegas randomized amortized update time of dynamic connectivity is (log (log log ) 2 ), which leaves a small (log log ) 2 gap between the cell probe lower bounds of Pǎtraşcu and Demaine [1] and Pǎtraşcu and Thorup [2]. The main bottleneck in our approach is dealing with insertions in the bu er trees inside local trees. Each a ects (log log ) local tree nodes, and the cost of updating such nodes involves adding (log ) ( oating point) approximate counters packed into (log log ) machine words. If this (log log ) 2 barrier were overcome, there would still be a log log -factor bottleneck, which arises from the shortcut infrastructure and the height of the bottom, bu er, and top trees.
It may be possible to achieve (log ) amortized time in the Monte Carlo model with a private connectivity witness, by using connectivity sketches [3,14,9,21,18].