Skip to main content

is_spider

Function is_spider 

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

Check whether a graph is a spider graph.

A spider is a tree with at most one vertex of degree ≥ 3. Every star and every path is a spider.

Directed graphs are treated as undirected.

§Examples

use rust_igraph::{Graph, is_spider};

// Star `S_3` is a spider
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
assert!(is_spider(&g).unwrap());

// Two adjacent high-degree vertices → NOT a spider
let mut g = Graph::with_vertices(7);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(0, 3).unwrap();
g.add_edge(3, 4).unwrap();
g.add_edge(3, 5).unwrap();
g.add_edge(3, 6).unwrap();
assert!(!is_spider(&g).unwrap());