Skip to main content

spectral_gap

Function spectral_gap 

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

Compute the spectral gap of a graph.

Δ = λ_1 - λ_2 — the difference between the largest and second-largest eigenvalue. A large spectral gap implies good expansion properties and rapid mixing of random walks.

Returns 0.0 if the graph has fewer than 2 vertices.

§Examples

use rust_igraph::{Graph, spectral_gap};

// K_3: eigenvalues {2, -1, -1} → gap = 2 - (-1) = 3
let g = Graph::from_edges(&[(0,1),(1,2),(0,2)], false, Some(3)).unwrap();
let gap = spectral_gap(&g).unwrap();
assert!((gap - 3.0).abs() < 0.01);