Guest
Sign in to keep your graphs and progress.
Select an algorithm and generate steps to begin visualization
Closeness that never divides by infinity
Adds up 1 / distance over all the other vertices: a closeness that stays defined when the graph is not connected
Select an algorithm and generate steps to begin visualization
Harmonic centrality measures how close a vertex is to all the others by adding up 1 / distance: a neighbour adds 1, a vertex two steps away 1/2, a vertex out of reach 0. Divided by n − 1, the score lies between 0 and 1. Closeness centrality instead divides by the sum of the distances, so a single unreachable vertex makes that sum infinite and the score useless unless it is patched. Marchiori and Latora used the harmonic form in 2000 for networks in pieces, and Boldi and Vigna showed in 2014 that it satisfies the axioms they proposed for a good centrality, where closeness does not.
The visualizer runs one shortest-path search per vertex, breadth-first search on an unweighted graph and Dijkstra's algorithm on a weighted one. On a directed graph it measures the distances to the vertex, along the edges that lead into it, the way closeness does in most libraries. Each step shows the distances as pills, the shortest-path tree to the vertex in green and the sum written out, for instance H(A) = (5×1/1 + 1/2 + ...) / 10. The panel keeps the harmonic scores beside the closeness scores, and vertices grow with their score. In the example, a hub with five neighbours and a long tail, closeness ranks F first because the far end of the tail costs A a lot, while harmonic centrality ranks A first: its five neighbours count fully and the far vertices count little.
Harmonic centrality is the closeness of choice whenever a graph may be disconnected: social networks with isolated groups, road networks cut by closures, directed graphs where many vertices cannot reach one another. Neo4j Graph Data Science, NetworkX and igraph provide it. It ranks hubs for spreading information, locates facilities and services that most places reach quickly, and compares how well connected the stations of a transport network are. Because near vertices dominate the sum, it rewards a vertex at the centre of a dense area more than one that sits between two distant parts, which betweenness centrality measures instead.
One shortest-path search per vertex, then a sum of reciprocals.
Harmonic(G):
for each vertex v:
run BFS to v (Dijkstra if weighted)
H(v) = sum of 1 / d(u, v) over the other vertices u
// a vertex that cannot reach v adds 1 / infinity = 0
H(v) = H(v) / (n - 1)
return HThe sum Σ 1 / d is n − 1 divided by the harmonic mean of the distances, hence the name. Closeness uses the arithmetic mean instead, (n − 1) / Σ d. An infinite distance makes the arithmetic mean infinite, but adds only 0 to the harmonic sum.
The star with a tail loaded on this page, 11 vertices.
Example graph: A is joined to B, C, D, E and F. From F a path runs F – G – H – I – J – K.
A 0.645, F 0.528, G 0.492, H 0.467, I 0.438. Harmonic centrality puts A first where closeness puts F first.
Time: O(n(n + m)) unweighted, O(n(n + m) log n) weighted · Space: O(n + m)
One breadth-first search costs O(n + m), and one runs per vertex. With weights each search is Dijkstra with a heap, O((n + m) log n). On large graphs this is too slow, so tools estimate the scores: HyperBall by Boldi and Vigna counts the vertices at each distance with small sketches, and sampling a few hundred sources gives good approximations of the ranking.
Distance-based centralities and when to use each.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Closeness | The graph is connected and a single far vertex should weigh in fully. It divides by the sum of the distances. | O(n(n + m)) |
| Wasserman–Faust closeness | A tool only offers closeness on a graph in pieces. It computes closeness inside each vertex's component and scales it by the share of vertices it reaches. | O(n(n + m)) |
| Betweenness | The question is which vertex lies on many shortest paths, a bridge or broker, rather than which is near everyone. | O(nm) unweighted |
Related algorithms: Closeness Centrality, Betweenness Centrality, Katz Centrality, Breadth-First Search, Dijkstra's Algorithm
Built by Mohammed Islam Hadjoudj · Work with me