Skip to main content

bipartivity_index

Function bipartivity_index 

Source
pub fn bipartivity_index(graph: &Graph) -> IgraphResult<f64>
Expand description

Compute the bipartivity index.

Uses a BFS greedy 2-coloring to partition vertices into two sets, then returns max(|A|, |B|) / n — the fraction of vertices in the larger partition. For a perfectly bipartite graph this equals the larger side fraction; for complete graphs it approaches 0.5. Returns 0.0 for empty graphs.

§Examples

use rust_igraph::{Graph, bipartivity_index};

// Path 0-1-2 is bipartite with partition {0,2} vs {1} → 2/3
let g = Graph::from_edges(&[(0,1),(1,2)], false, Some(3)).unwrap();
assert!((bipartivity_index(&g).unwrap() - 2.0/3.0).abs() < 1e-10);