Home > theory > Random Spanning Trees

Random Spanning Trees

BigRedBits is again pleased to have Igor Gorodezky as a guest blogger directly from UCLA. I leave you with his excelent post on the Wilson’s algorithm.


Igor again, with another mathematical dispatch from UCLA, where I’m spending the semester eating and breathing combinatorics as part of the 2009 program on combinatorics and its applications at IPAM. In the course of some reading related to a problem with which I’ve been occupying myself, I ran across a neat algorithmic result – Wilson’s algorithm for uniformly generating spanning trees of a graph. With Renato’s kind permission, let me once again make myself at home here at Big Red Bits and tell you all about this little gem.

The problem is straightforward, and I’ve essentially already stated it: given an undirected, connected graph {G}, we want an algorithm that outputs uniformly random spanning trees of {G}. In the early ’90s, Aldous and Broder independently discovered an algorithm for accomplishing this task. This algorithm generates a tree {T} by, roughly speaking, performing a random walk on {G} and adding the edge {(u,v)} to {T} every time that the walk steps from {u} to {v} and {v} is a vertex that has not been seen before.

Wilson’s algorithm (D. B. Wilson, “Generating random spanning trees more quickly than the cover time,” STOC ’96) takes a slightly different approach. Let us fix a root vertex {r}. Wilson’s algorithm can be stated as a loop-erased random walk on {G} as follows.

Algorithm 1 (Loop-erased random walk) Maintain a tree {T}, initialized to consist of {r} alone. While there remains a vertex {v} not in {T}: perform a random walk starting at {v}, erasing loops as they are created, until the walk encounters a vertex in {T}, then add to {T} the cycle-erased simple path from {v} to {T}.

We observe that the algorithm halts with probability 1 (its expected running time is actually polynomial, but let’s not concern ourselves with these issues here), and outputs a random directed spanning tree oriented towards {r}. It is a minor miracle that this tree is in fact sampled uniformly from the set of all such trees. Let us note that this offers a solution to the original problem, as sampling {r} randomly and then running the algorithm will produce a uniformly generated spanning tree of {G}.

It remains, then, to prove that the algorithm produces uniform spanning trees rooted at {r} (by which we mean directed spanning trees oriented towards {r}). To this we dedicate the remainder of this post.

1. A “different” algorithm

Wilson’s proof is delightfully sneaky: we begin by stating and analyzing a seemingly different algorithm, the cycle-popping algorithm. We will prove that this algorithm has the desired properties, and then argue that it is equivalent to the loop-erased random walk (henceforth LERW).

The cycle-popping algorithm works as follows. Given {G} and {r}, associate with each non-root vertex {v} an infinite stack of neighbors. More formally, to each {v \neq r} we associate

\displaystyle  \mathcal S_v = [u_{0}, u_{1}, \dots ]

where each {u_{i}} is uniformly (and independently) sampled from the set of neighbors of {v}. Note that each stack is not a random walk, just a list of neighbors. We refer to the left-most element above as the top of {\mathcal S_v}, and by popping the stack {\mathcal S_v} we mean removing this top vertex from {\mathcal S_v}.

Define the stack graph {G_{\mathcal S}} to be the directed graph on {V} that has an edge from {v} to {u} if {u} is at the top of the stack {\mathcal S_v}. Clearly, if {G} has {n} vertices then {G_{\mathcal S}} is an oriented subgraph of {G} with {n-1} edges. The following lemma follows immediately.

Lemma 1 Either {G_{\mathcal S}} is a directed spanning tree oriented towards {r} or it contains a directed cycle.

If there is a directed cycle {C} in {G_{\mathcal S}} we may pop it by popping {\mathcal S_v} for every {v \in C}. This eliminates {C}, but of course might create other directed cycles. Without resolving this tension quite yet, let us go ahead and formally state the cycle-popping algorithm.

Algorithm 2 (Cycle-popping algorithm) Create a stack {\mathcal S_v} for every {v \neq r}. While {G_{\mathcal S}} contains any directed cycles, pop a cycle from the stacks. If this process ever terminates, output {G_{\mathcal S}}.

Note that by the lemma, if the algorithm ever terminates then its output is a spanning tree rooted at {r}. We claim that the algorithm terminates with probability 1, and moreover generates spanning trees rooted at {r} uniformly.

To this end, some more definitions: let us say that given a stack {\mathcal S_v}, the vertex {u_i} is at level {i}. The level of a vertex in a stack is static, and is defined when the stack is created. That is, the level of {u_i} does not change even if {u_i} advances to the top of the stack as a result of the stack getting popped.

We regard the sequence of stack graphs produced by the algorithm as leveled stack graphs: each non-root vertex {v} is assigned the level of its stack. Observe that the level of {v} in {G_{\mathcal S}} is the number of times that {\mathcal S_v} has been popped. In the same way, we regard cycles encountered by the algorithm as leveled cycles, and we can regard the tree produced by the algorithm (if indeed one is produced) as a leveled tree.

The analysis of the algorithm relies on the following key lemma (Theorem 4 in Wilson’s paper), which tells us that the order in which the algorithm pops cycles is irrelevant.

Lemma 2 For a given set of stacks, either the cycle-popping algorithm never terminates, or there exists a unique leveled spanning tree {T} rooted at {r} such that the algorithm outputs {T} irrespective of the order in which cycles are popped.

Proof: Fix a set of stacks {\{ \mathcal S_v \}_{v \neq r}}. Consider a leveled cycle {C} that is pop-able, i.e.~there exist leveled cycles {C_1, C_2, \dots, C_k=C} that can be popped in sequence. We claim that if the algorithm pops any cycle not equal to {C}, then there still must exist a series of cycles that ends in {C} and that can be popped in sequence. In other words, if {C} is pop-able then it remains pop-able, no matter which cycles are popped, until {C} itself is actually popped.

Let {C'} be a cycle popped by the algorithm. If {C'=C_1} then the claim is clearly true. Also, if {C'} shares no vertices with {C_1, \dots, C_k}, then the claim is true again. So assume otherwise, and let {C_i} be the first in the series {C_1, \dots, C_k} to share a vertex with {C'}. Let us show that {C'=C_i} by contradiction.

If {C_i \neq C'}, then {C_i} and {C'} must share a vertex {w} that has different successors in {C'} and {C_i}. But by definition of {C_i}, none of the {C_1, \dots, C_{i-1}} contain {w}, and this implies that {w} has the same level in {C'} and {C_i}. Therefore its successor in both cycles is the same, a contradiction. This proves {C_i=C'}.

Moreover, the argument above proves that {C_i} and {C'} are equal as leveled cycles (i.e.~every vertex has the same level in both cycles). Hence

\displaystyle  C'=C_i, C_1, C_2, \dots, C_{i-1}, C_{i+1}, \dots, C_k=C

is a series of cycles that can be popped in sequence, which proves the original claim about {C}.

We conclude that given a set of stacks, either there is an infinite number of pop-able cycles, in which case there will always be an infinite number and the algorithm will never terminate, or there is a finite number of such cycles. In the latter case, every one of these cycles is eventually popped, and the algorithm produces a spanning tree {T} rooted at {r}. The level of each non-root vertex in {T} is given by (one plus) the number of popped cycles that contained {v}. \Box

Wilson summarizes the cycle-popping algorithm thusly: “[T]he stacks uniquely define a tree together with a partially ordered set of cycles layered on top of it. The algorithm peels off these cycles to find the tree.”

Theorem 3 The cycle-popping algorithm terminates with probability 1, and the tree that it outputs is a uniformly sampled spanning tree rooted at {r}.

Proof: The first claim is easy: {G} has a spanning tree, therefore it has a directed spanning tree oriented towards {r}. The stacks generated in the first step of the algorithm will contain such a tree, and hence the algorithm will terminate, with probability 1.

Now, consider a spanning tree {T} rooted at {r}. We’ll abuse notation and let {T} be the event that {T} is produced by the algorithm. Similarly, given a collection of leveled cycles {\mathcal C}, we will write {\mathcal C} for the event that {\mathcal C} is the set of leveled cycles popped by the algorithm before it terminates. Finally, let {\mathcal C \wedge T} be the event that the algorithm popped the leveled cycles in {\mathcal C} and terminated, with the resulting leveled tree being equal to {T}.

By the independence of the stack entries, we have {\Pr[\mathcal C \wedge T] = \Pr[\mathcal C] \cdot p}, where {p} is the probability that the algorithm’s output is a leveled version of {T}, a quantity which a moment’s reflection will reveal is independent of {T}. Now,

\displaystyle  \Pr[T] = \sum_{\mathcal C} \Pr[\mathcal C \wedge T] = p \sum_{\mathcal C} \Pr[\mathcal C]

which, as desired, is independent of {T}. \Box

2. Conclusion

We have shown that the cycle-popping algorithm generates spanning trees rooted at {r} uniformly. It remains to observe that the LERW algorithm is nothing more than an implementation of the cycle-popping algorithm! Instead of initially generating the (infinitely long) stacks and then looking for cycles to pop, the LERW generates stack elements as necessary via random walk (computer scientists might recognize this as the Principle of Deferred Decisions). If the LERW encounters a loop, then it has found a cycle in the stack graph {G_{\mathcal S}} induced by the stacks that the LERW has been generating. Erasing the loop is equivalent to popping this cycle. We conclude that the LERW algorithm generates spanning trees rooted at {r} uniformly.

Categories: theory Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.