Skip to main content

terminal_wiener_index

Function terminal_wiener_index 

Source
pub fn terminal_wiener_index(graph: &Graph) -> IgraphResult<u64>
Expand description

Compute the terminal Wiener index.

TW(G) = Σ_{u<v, d(u)=d(v)=1} dist(u,v)

Sum of distances between all pairs of pendant (degree-1) vertices. Returns 0 if fewer than 2 pendant vertices exist.

§Examples

use rust_igraph::{Graph, terminal_wiener_index};

// Star S₄ (center 0, leaves 1-4): leaves are all at distance 2
// C(4,2) = 6 pairs, each distance 2 → TW = 12
let g = Graph::from_edges(&[(0,1),(0,2),(0,3),(0,4)], false, Some(5)).unwrap();
assert_eq!(terminal_wiener_index(&g).unwrap(), 12);