Skip to main content

tree_graph

Function tree_graph 

Source
pub fn tree_graph<R: Rng>(n: usize, rng: &mut R) -> Result<Graph<usize, f64>>
Expand description

Generates a random tree with n nodes

Uses a random process to connect nodes while maintaining the tree property (connected and acyclic). Each tree has exactly n-1 edges.

§Arguments

  • n - Number of nodes
  • rng - Random number generator

§Returns

  • Result<Graph<usize, f64>> - A random tree with nodes 0, 1, …, n-1