Skip to main content

is_threshold_graph

Function is_threshold_graph 

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

Check whether a graph is a threshold graph.

A threshold graph is built from a single vertex by repeatedly adding isolated or dominating vertices. Uses a degree-sequence peeling algorithm for O(V log V) recognition.

Returns false for directed graphs, multigraphs, or graphs with self-loops (the characterization requires simple undirected graphs).

An empty graph (0 vertices) is a threshold graph (vacuously). An edgeless graph is a threshold graph (all vertices are isolated). A complete graph is a threshold graph (all vertices are dominating).

ยงExamples

use rust_igraph::{Graph, is_threshold_graph};

// Star K_{1,3}: built as isolated, then dominating
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_threshold_graph(&g).unwrap());

// Path P4 (0-1-2-3) is NOT threshold
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_threshold_graph(&g).unwrap());