Skip to main content

random_spanning_tree

Function random_spanning_tree 

Source
pub fn random_spanning_tree(graph: &Graph, seed: u64) -> Option<Graph>
Expand description

Generate a uniformly random spanning tree using Wilson’s algorithm.

Uses loop-erased random walks to generate a spanning tree uniformly at random from the set of all spanning trees. The algorithm runs in O(n * mean_hitting_time) expected time.

Returns None if the graph is empty or not connected.

§Arguments

  • graph - undirected graph (must be connected)
  • seed - random seed for reproducibility

Matches networkx.random_spanning_tree(G, ...).