Wilson's algorithm (source code)

= Wilson's algorithm
{c}
{wiki}

= Wilson algorithm
{c}
{synonym}

For a finite <connected graph>, <Wilson's algorithm> starts with a chosen root as the current <tree>. Choose an unvisited <vertex>, run a <random walk> until it hits the current <tree>, erase loops in chronological order, and attach the resulting simple <path>. Repeat until every <vertex> belongs to the <tree>.

Each attached <path> has no repeated <vertices> and first meets the old <tree> at its endpoint, so attachment preserves <connectedness> and cannot create a <graph cycle>. Finiteness and <connectedness> make each hitting time finite <almost surely>. The output is a <uniform spanning tree>, and its law does not depend on the order in which starting <vertices> were chosen.

For positive <electrical conductances> $c_{xy}$, use transition <probabilities> $c_{xy}/\sum_zc_{xz}$. The output then has <probability> proportional to $\prod_{e\in T}c_e$. The proof uses cycle popping: independent stacks of prospective outgoing <edges> can be exposed and cyclic choices discarded in any order without changing the final rooted <tree>.<Generating Random Spanning Trees More Quickly than the Cover Time by David Bruce Wilson>[RandomTreeWithRoot and cycle-popping correctness argument]{ref}