Algorithm Search⌘K

Proofs: Offline dynamic connectivity

These are the human proofs of Offline dynamic connectivity, at full length.

The walk over the segment tree answers every query on the graph of its time full

This proof shows: correctness.

Let GtG_t be the multigraph of the edges present after the operations o0,…,oto_0, \ldots, o_t. For a node xx of the segment tree, let R(x)⊆[0,T)R(x) \subseteq [0, T) be its range, let L(x)L(x) be its list of edge copies, and let anc(x)\mathrm{anc}(x) be the set of nodes on the path from the root to xx, including xx.

Lemma 1 (lifetimes). A copy of an edge with lifetime [a,d)[a, d) is present in GtG_t if and only if a≤t<da \le t < d.

Proof. Line L1 pairs each removal of {u,v}\{u, v\} with the latest open start time of a copy of {u,v}\{u, v\}, and a copy that is never removed gets the end TT. The copy is inserted by oao_a, so it is in GtG_t for t≥at \ge a, and it is deleted by odo_d, so it is not in GtG_t for t≥dt \ge d. Since all copies of one edge are equal, the choice of which copy a removal deletes does not change the multigraph GtG_t. □\square

Lemma 2 (canonical nodes). For a lifetime I=[a,d)I = [a, d) and a leaf ℓ\ell of time tt, exactly one canonical node of II is in anc(ℓ)\mathrm{anc}(\ell) if t∈It \in I, and none is if t∉It \notin I.

Proof. Line L2 puts the copy at a set CC of nodes whose ranges are pairwise disjoint and have the union II; this is the property of the standard segment tree decomposition. The ranges of the nodes in anc(ℓ)\mathrm{anc}(\ell) are exactly the ranges of the tree that contain tt. If t∈It \in I, some node of CC has a range that contains tt, and only one does, since the ranges of CC are disjoint. If t∉It \notin I, no range of CC contains tt. □\square

So the multiset E(ℓ)=⋃y∈anc(ℓ)L(y)E(\ell) = \bigcup_{y \in \mathrm{anc}(\ell)} L(y) is the edge multiset of GtG_t, by Lemmas 1 and 2.

Lemma 3 (the walk). When VISIT(x)(x) starts, the union-find DD is in the state reached from nn singletons by the unions of the edges in ⋃y∈anc(x)∖{x}L(y)\bigcup_{y \in \mathrm{anc}(x) \setminus \{x\}} L(y). When VISIT(x)(x) ends, DD is in the same state as when it started.

Proof. By induction on the height of xx. Let SS be the state when VISIT(x)(x) starts, and let hh be the log height saved in line L3. Line L4 applies the unions of L(x)L(x), so DD is now the state of the unions of the edges of anc(x)\mathrm{anc}(x). If xx is internal, VISIT of the left child starts in this state, as the claim for the child needs, and by the induction hypothesis it ends in the same state; the same holds for the right child. Line L7 then undoes every union recorded after height hh. Each union records the two fields it wrote, and the undo restores them in the reverse order, so by the correctness of the rollback technique the state returns to SS. At the root, the start state is nn singletons, which matches the empty set of ancestors. □\square

Theorem. For each time tt whose operation is a query, the answer at the leaf of tt is the answer for GtG_t.

Proof. By Lemma 3, after line L4 at the leaf ℓ\ell of tt, the union-find holds the unions of the edges in E(ℓ)E(\ell), which is the edge multiset of GtG_t. The sets of a union-find after the unions of an edge set are the connected components of the graph of those edges: two vertices are in one set if and only if a chain of the unioned edges joins them, and union by size changes only the shape of the trees, not the sets. So find(u)=find(v)\mathrm{find}(u) = \mathrm{find}(v) if and only if uu and vv are connected in GtG_t. The component counter starts at nn, decreases by one exactly at each union that merges two sets, and is restored by each undo, so it equals the number of components of GtG_t. Line L5 reads these values. The leaves are visited in the order of time, left before right, so the answers come out in the order of the queries. ■\blacksquare

Back to Offline dynamic connectivity