Skip to main content

tree_game_prufer

Function tree_game_prufer 

Source
pub fn tree_game_prufer(n: u32, seed: u64) -> IgraphResult<Graph>
Expand description

Generate a uniformly random labelled tree on n vertices using the Prüfer sequence method.

Samples a random Prüfer sequence of length n - 2 (each entry uniform in [0, n)), then decodes it with from_prufer to produce an undirected labelled tree.

  • n — vertex count. n = 0 returns an empty graph, n = 1 returns a single isolated vertex.
  • seed — initialises an internal SplitMix64 PRNG. Same (n, seed) always yields the same tree.

The output has exactly max(0, n - 1) edges, is acyclic, has no self-loops, and is connected.

Counterpart of the IGRAPH_RANDOM_TREE_PRUFER branch of igraph_tree_game() in references/igraph/src/games/tree.c:37-56.

§Errors

§Examples

use rust_igraph::tree_game_prufer;

let g = tree_game_prufer(30, 0xC0FF_EE00).unwrap();
assert_eq!(g.vcount(), 30);
assert_eq!(g.ecount(), 29);
assert!(!g.is_directed());