Skip to main content

is_distance_hereditary

Function is_distance_hereditary 

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

Check whether a graph is distance-hereditary.

Uses a pruning algorithm: repeatedly remove pendant vertices (degree 1) and twin vertices until the graph is empty or no more removals are possible. O(V^2) in the worst case.

Returns false for directed graphs.

An empty graph (0 vertices) is distance-hereditary (vacuously). A single vertex is distance-hereditary. Any tree is distance-hereditary. Any block graph is distance-hereditary.

ยงExamples

use rust_igraph::{Graph, is_distance_hereditary};

// Tree: distance-hereditary
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_distance_hereditary(&g).unwrap());

// C5 is NOT distance-hereditary
let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 4).unwrap();
g.add_edge(4, 0).unwrap();
assert!(!is_distance_hereditary(&g).unwrap());