pub fn is_pseudo_forest(graph: &Graph) -> IgraphResult<bool>Expand description
Check whether a graph is a pseudo-forest.
A pseudo-forest has at most one cycle per connected component. This is equivalent to requiring |E| <= |V| for every component.
Returns false for directed graphs.
An empty graph (0 vertices) is a pseudo-forest (vacuously). An edgeless graph is a pseudo-forest (forest with no edges). A single cycle is a pseudo-forest.
§Examples
use rust_igraph::{Graph, is_pseudo_forest};
// Triangle: one component with |E|=3, |V|=3 → pseudo-forest
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
assert!(is_pseudo_forest(&g).unwrap());
// K4: |E|=6, |V|=4 → NOT pseudo-forest
let mut g = Graph::with_vertices(4);
for u in 0..4u32 {
for v in (u + 1)..4 {
g.add_edge(u, v).unwrap();
}
}
assert!(!is_pseudo_forest(&g).unwrap());