Skip to main content

is_cactus_graph

Function is_cactus_graph 

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

Check whether a graph is a cactus graph.

A cactus graph is a connected graph where every biconnected component is either a single edge (bridge) or a simple cycle.

An empty graph (0 vertices) is considered a cactus (vacuously). A single vertex with no edges is a cactus. A graph that is not connected is NOT a cactus.

For directed graphs, connectivity is checked as weak connectivity and edges are treated as undirected for the biconnected component decomposition.

ยงExamples

use rust_igraph::{Graph, is_cactus_graph};

// Triangle is a cactus (one cycle component)
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_cactus_graph(&g).unwrap());

// K4 is NOT a cactus (biconnected component has too many edges)
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_cactus_graph(&g).unwrap());