Algorithm Search⌘K

Proofs: Rake-compress tree

These are the human proofs of Rake-compress tree, at full length.

The RC-tree represents the forest, and its queries are correct full

This proof shows: correctness.

Let FF be the forest with positive or arbitrary integer weights, and fix the coins. For a cluster KK, let E(K)E(K) be its set of edges and V(K)V(K) the set of the ends of those edges, together with the vertex vv if K=C(v)K = C(v). Write d(x,y)d(x, y) for the weight of the tree path from xx to yy.

Lemma 1 (no conflicts). In one round, no two adjacent live vertices are both removed, and no vertex is both chosen and the target of a rake.

Proof. A finalized vertex has no live neighbor. If a leaf vv rakes into uu and uu is also removed, then uu is not compressed, since a compressing vertex has no leaf neighbor, and uu is not finalized, so uu rakes, which means uu is a leaf whose only neighbor is vv. Then both are leaves and only the smaller one rakes, a contradiction. Two adjacent compressing vertices would both have heads while each needs the other to have tails. □\square

So each round is a set of independent local changes, and their order inside the round does not matter.

Invariant (I). After every round, with LL the live vertices and T\mathcal{T} the top clusters (clusters with no parent yet):

  1. the sets E(K)E(K) for K∈TK \in \mathcal{T} partition E(F)E(F);
  2. each binary K∈TK \in \mathcal{T} is a live edge between its two boundary vertices a,b∈La, b \in L, E(K)E(K) is the edge set of a subtree of FF that contains the path from aa to bb, and its stored weight is d(a,b)d(a, b);
  3. each unary K∈TK \in \mathcal{T} hangs on one live vertex uu, its boundary, and E(K)E(K) is the edge set of a subtree of FF that contains uu;
  4. two distinct clusters of T\mathcal{T} share no vertex except a common boundary vertex, and every vertex of V(K)∖bound(K)V(K) \setminus \mathrm{bound}(K) is removed;
  5. two live vertices are in one tree of the live forest if and only if they are in one tree of FF.

Proof. Before round 1, the top clusters are the base clusters, all vertices are live, and the live forest is FF; all items hold. Assume (I) before a round. By Lemma 1 we may apply the removals one at a time.

A finalize of vv joins the unary clusters hanging on vv, and no binary cluster since vv has no live edge, into C(v)C(v) with no boundary. By item 4 these clusters meet only at vv, so E(C(v))E(C(v)) is connected and is a subtree; nothing else changes.

A rake of vv into uu joins the live edge KuvK_{uv} and the unary clusters on vv into C(v)C(v) with boundary {u}\{u\}. Each part is a subtree containing vv (items 2 and 3), so the union is a subtree containing uu. The vertex vv leaves LL; any other vertex of V(C(v))V(C(v)) was already interior to a part, hence removed. Removing a leaf does not change connectivity among the other live vertices.

A compress of vv with live edges KavK_{av} and KvbK_{vb} joins them and the unary clusters on vv into C(v)C(v) with boundary {a,b}\{a, b\}. The union is a subtree that contains the path from aa to vv and the path from vv to bb. These two paths share only vv, because KavK_{av} and KvbK_{vb} share only vv (item 4), so their union is the path from aa to bb, and d(a,b)=d(a,v)+d(v,b)d(a, b) = d(a, v) + d(v, b), the stored sum. The live forest replaces the path a,v,ba, v, b by the edge abab, which keeps connectivity among the live vertices.

In all three cases the new cluster takes the place of its parts in T\mathcal{T}, so item 1 holds, and it shares with other top clusters only its boundary vertices, which gives item 4. □\square

Termination. In each round with a live vertex, the live forest has a vertex vv of degree at most one. If vv is isolated it is finalized; if it is a leaf with neighbor uu, then vv rakes, or uu is a leaf with u<vu < v and uu rakes. So some vertex is removed in every round, so the number of live vertices strictly drops, and the loop ends. When it ends, LL is empty, every top cluster has no boundary, and every vertex vv owns the cluster C(v)C(v) made when it was removed.

Lemma 2 (connectivity). uu and vv are in one tree of FF if and only if C(u)C(u) and C(v)C(v) have the same root.

Proof. By item 5 and induction over the rounds, the vertices of one tree of FF stay in one live tree until the last of them is finalized, and the clusters on them are joined into the cluster of that last vertex; clusters of different trees never meet, because a new cluster only joins clusters at a common live vertex or a live edge, which lie in one tree. The cluster of a finalized vertex has no parent. So each tree of FF gives exactly one root, and C(x)C(x) lies below the root of the tree of xx because x∈V(C(x))x \in V(C(x)) and clusters only grow upward. □\square

Lemma 3 (containment). Let uu be a vertex and K=C(z)K = C(z) a cluster on the path from C(u)C(u) to its root. Then u∈V(K)u \in V(K), and for every x∈{z}∪bound(K)x \in \{z\} \cup \mathrm{bound}(K) the tree path from uu to xx uses only edges of E(K)E(K).

Proof. E(K)E(K) is the edge set of a subtree that contains uu, zz and the boundary vertices (items 2 and 3 at the time KK is made, and u∈V(C(u))⊆V(K)u \in V(C(u)) \subseteq V(K)). In a tree, the path between two vertices of a subtree stays in the subtree. □\square

Lemma 4 (the climb). In the walk up from C(u)C(u), after reaching K=C(z)K = C(z), the value stored for each x∈{z}∪bound(K)x \in \{z\} \cup \mathrm{bound}(K) is d(u,x)d(u, x).

Proof. At K=C(u)K = C(u): d(u,u)=0d(u, u) = 0, and each boundary vertex xx of C(u)C(u) is the other end of a binary child BB of C(u)C(u) with boundary {u,x}\{u, x\}, since bound(C(u))\mathrm{bound}(C(u)) is the set of boundary vertices of its children other than uu; by item 2, d(u,x)d(u, x) is the weight of BB.

Step from a child K′K' to its parent K=C(z)K = C(z), assuming the claim for K′K'. The vertex zz is a boundary vertex of K′K', so d(u,z)d(u, z) is known. Let x∈bound(K)x \in \mathrm{bound}(K). If x∈bound(K′)x \in \mathrm{bound}(K'), its value is already d(u,x)d(u, x). Otherwise xx is the other end of a binary child B≠K′B \neq K' of KK with boundary {z,x}\{z, x\}. By Lemma 3 the path from uu to xx lies in E(K)E(K). It starts in E(K′)E(K') and ends at a vertex not in V(K′)V(K'), since by item 4 the only vertices K′K' shares with BB are common boundary vertices, and x∉bound(K′)x \notin \mathrm{bound}(K'). The children of KK meet only at zz, so the path leaves K′K' through zz and then follows the path from zz to xx, which lies in BB. Hence d(u,x)=d(u,z)+w(B)d(u, x) = d(u, z) + w(B), which is the value set. □\square

Lemma 5 (meeting point). Let u≠vu \neq v be connected, and let K=C(z)K = C(z) be the first cluster on the walk up from C(v)C(v) that is also on the walk up from C(u)C(u). Then d(u,v)=d(u,z)+d(z,v)d(u, v) = d(u, z) + d(z, v).

Proof. By Lemma 2 such a KK exists. If u=zu = z or v=zv = z the claim is trivial. Otherwise uu lies in a child AA of KK and vv in a child BB of KK, with A≠BA \neq B by the choice of KK. By Lemma 3 the path from uu to vv lies in E(K)E(K). All children of KK have zz in their boundary, and by item 4 at the time KK was made, two of them share only the vertex zz. Inside the subtree E(K)E(K), which is the union of the children's subtrees, the path from a vertex of AA to a vertex of BB must therefore pass through zz. □\square

Theorem. After any sequence of links and cuts, connected(u,v)(u, v) is true exactly when uu and vv are in one tree, and path weight(u,v)(u, v) returns d(u,v)d(u, v) for connected uu and vv.

Proof. Each update rebuilds the contraction for the current forest, so (I) and the lemmas apply to it. Connectivity is Lemma 2. For path weight, the walk from C(v)C(v) stops at the cluster C(z)C(z) of Lemma 5, and by Lemma 4 applied to both walks the returned value is d(u,z)+d(z,v)=d(u,v)d(u, z) + d(z, v) = d(u, v); for u=vu = v the walk stops at C(u)C(u) and returns 0+00 + 0. ■\blacksquare

Back to Rake-compress tree