Skip to main content

is_diamond_free

Function is_diamond_free 

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

Check whether a graph is diamond-free.

A diamond-free graph has no induced K_4 minus one edge. The diamond has vertices {a, b, c, d} with edges {ab, ac, ad, bc, bd} (c and d not adjacent).

Returns false for directed graphs.

ยงExamples

use rust_igraph::{Graph, is_diamond_free};

// Triangle is diamond-free
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_diamond_free(&g).unwrap());

// Diamond: `K_4` minus edge 2-3
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();
g.add_edge(1, 2).unwrap();
g.add_edge(1, 3).unwrap();
assert!(!is_diamond_free(&g).unwrap());