Skip to main content

is_star

Function is_star 

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

Check whether a graph is a star graph.

A star graph has one center vertex connected to all other vertices, with no other edges. K_{1,0} (single vertex) and K_{1,1} (single edge) are considered stars.

Returns false for directed graphs and the empty graph (no vertices).

ยงExamples

use rust_igraph::{Graph, is_star};

// K_{1,4}: center 0 with 4 leaves
let mut g = Graph::with_vertices(5);
for i in 1..5u32 {
    g.add_edge(0, i).unwrap();
}
assert!(is_star(&g).unwrap());

// Path P_3 is NOT a star (middle vertex has degree 2, not n-1=2... wait
// P_3 has 3 vertices, center degree should be 2. Actually P_3 IS K_{1,2}!)
// Use P_4 as negative example instead.
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
assert!(!is_star(&g).unwrap());