Skip to main content

from_prufer

Function from_prufer 

Source
pub fn from_prufer(prufer: &[u32]) -> IgraphResult<Graph>
Expand description

Decode a Prüfer sequence into the unique labelled tree it represents.

prufer must contain values in [0, n) where n = prufer.len() + 2. The resulting graph has exactly n vertices and n - 1 undirected edges, forming a tree. The empty input slice produces the 2-vertex path graph P_2.

§Errors

§Examples

use rust_igraph::from_prufer;

// Prüfer sequence [2, 3, 2, 3] encodes a 6-vertex tree.
let tree = from_prufer(&[2, 3, 2, 3]).unwrap();
assert_eq!(tree.vcount(), 6);
assert_eq!(tree.ecount(), 5);
assert!(!tree.is_directed());