Skip to main content

is_complete_multipartite

Function is_complete_multipartite 

Source
pub fn is_complete_multipartite(graph: &Graph) -> IgraphResult<Option<Vec<u32>>>
Expand description

Check whether a graph is a complete multipartite graph.

A complete multipartite graph has vertices partitioned into independent sets where every two vertices in different parts are adjacent. Equivalently, the complement is a disjoint union of cliques.

Returns false for directed graphs and non-simple graphs. Returns true for the empty graph (vacuously), single vertex, complete graphs (single part of size 0 with all vertices in other parts, or equivalently k parts of size 1), and edgeless graphs (single part containing all vertices).

If the graph is complete multipartite, returns Some(parts) where parts is a sorted vector of part sizes. Returns None otherwise.

ยงExamples

use rust_igraph::{Graph, is_complete_multipartite};

// K_{2,3}: complete bipartite
let mut g = Graph::with_vertices(5);
for i in 0..2u32 {
    for j in 2..5u32 {
        g.add_edge(i, j).unwrap();
    }
}
let parts = is_complete_multipartite(&g).unwrap();
assert_eq!(parts, Some(vec![2, 3]));

// Triangle K_3 = K_{1,1,1}
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();
let parts = is_complete_multipartite(&g).unwrap();
assert_eq!(parts, Some(vec![1, 1, 1]));