Skip to main content

is_apex_forest

Function is_apex_forest 

Source
pub fn is_apex_forest(graph: &Graph) -> IgraphResult<bool>
Expand description

Check whether a graph is an apex forest.

A graph is an apex forest if removing some single vertex yields a forest. Tests each vertex as a candidate apex.

Directed graphs are treated as undirected.

§Examples

use rust_igraph::{Graph, is_apex_forest};

// Triangle: remove any vertex → single edge (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_apex_forest(&g).unwrap());

// Two disjoint triangles: no single vertex removal yields forest
let mut g = Graph::with_vertices(6);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
g.add_edge(3, 4).unwrap();
g.add_edge(4, 5).unwrap();
g.add_edge(5, 3).unwrap();
assert!(!is_apex_forest(&g).unwrap());