Skip to main content

square_density

Function square_density 

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

Compute the square (4-cycle) density of the graph.

Number of distinct 4-cycles divided by C(n, 4) for n ≥ 4.

A 4-cycle is an induced cycle on 4 vertices (no chord). Counted via non-adjacent pairs sharing common neighbors: each pair of common neighbors of a non-edge (u,v) forms a 4-cycle u-w1-v-w2-u provided w1-w2 are not adjacent. Returns 0.0 for n < 4.

§Examples

use rust_igraph::{Graph, square_density};

// C_4: exactly 1 chordless 4-cycle, C(4,4)=1 → 1.0
let g = Graph::from_edges(&[(0,1),(1,2),(2,3),(3,0)], false, Some(4)).unwrap();
assert!((square_density(&g).unwrap() - 1.0).abs() < 1e-10);