Skip to main content

is_apex_tree

Function is_apex_tree 

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

Check whether a graph is an apex tree.

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

Directed graphs are treated as undirected.

§Examples

use rust_igraph::{Graph, is_apex_tree};

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

// Two disjoint triangles: no single vertex removal yields tree
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_tree(&g).unwrap());