Guest User
Using app without sign in

Practice book
Graph Theory Through Problems300 Exercises with Hints, Worked Algorithms and Complete Solutions
By Mohammed Islam Hadjoudj
Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
Which vertices sit on the most shortest paths?
Share of shortest paths through each vertex, with Brandes' algorithm: one search per source, dependencies added back from the farthest vertex
Select an algorithm and generate steps to begin visualization
Betweenness centrality measures how often a vertex lies on the shortest paths between other vertices. A vertex with high betweenness is a broker or a bottleneck: much of the traffic between other parts of the network has to pass through it, even if it has few connections of its own. Linton Freeman defined it in 1977 for social networks, and Ulrik Brandes' algorithm of 2001 made it practical for large graphs.
For each source vertex s, a breadth-first search (Dijkstra's algorithm when edges are weighted) finds the distance to every vertex and σ(v), the number of shortest paths from s to v: each vertex adds up σ over its predecessors. Then the vertices are visited from the farthest back to s, and each passes its dependency δ to its predecessors in proportion to σ: δ(v) gains σ(v)/σ(w) × (1 + δ(w)) from every w that follows it. Adding δ(v) over all sources gives the betweenness of v. For undirected graphs each pair is counted twice, so the result is halved. The whole computation takes O(VE) time instead of looking at every pair of vertices separately.
Betweenness finds influential brokers in social and organisational networks, critical routers and links in communication networks, bottleneck stations in transport networks and key proteins in biological networks. Its edge version drives the Girvan-Newman method for community detection. It is a standard topic in network science courses, together with degree, closeness and PageRank.
Brandes' algorithm computes the betweenness of every vertex without enumerating shortest paths. One BFS per source counts paths, and a backward pass over the same BFS order accumulates how much each vertex depends on the others.
Brandes(graph):
CB[v] = 0 for every v
for each source s:
BFS from s, recording for every v:
sigma[v] = number of shortest s - v paths
pred[v] = predecessors of v on those paths
stack = vertices in order of distance
delta[v] = 0 for every v
while stack is not empty:
w = stack.pop() // farthest first
for each v in pred[w]:
delta[v] += sigma[v] / sigma[w] * (1 + delta[w])
if w != s: CB[w] += delta[w]
halve every CB[v] if the graph is undirected
return CBdelta[v] is the dependency of the source s on v: the sum, over all targets, of the fraction of shortest s-paths to that target that pass through v. The recursion works because a shortest path through v to a far target must continue through one of the successors w of v, and v carries the share sigma[v] / sigma[w] of the paths into w.
Compute betweenness on the example this page loads, Krackhardt's kite, a ten-person network built to show that three classic centralities pick three different winners.
Example graph: Undirected edges A-B, A-C, A-D, A-F, B-D, B-E, B-G, C-D, C-F, D-E, D-F, D-G, E-G, F-G, F-H, G-H, H-I and I-J. Seven people form the kite, and H, I and J form its tail.
D has six neighbours, the most in the network, yet its betweenness is only 3.67, because the kite is so densely connected that most pairs have shortcuts that avoid D. F and G are closest to everyone, but H is the broker: remove it and the tail is cut off. Normalised by (n - 1)(n - 2) / 2 = 36 pairs, H scores 0.389. This is the canonical illustration that degree, closeness and betweenness measure different things.
Time: O(VE) unweighted, O(VE + V^2 log V) weighted · Space: O(V + E)
For each of the V sources, the BFS costs O(V + E) and the backward accumulation visits each predecessor link once, also O(V + E). That gives O(V (V + E)), which is O(VE) on a connected graph. For weighted graphs the BFS becomes Dijkstra, at O(E + V log V) per source. Memory is reused between sources, so only O(V + E) is needed at any time. The naive method of counting pairs and paths directly costs O(V^3) even with Floyd-Warshall, which is why Brandes 2001 made betweenness practical on networks with tens of thousands of vertices.
Centrality measures answer different questions. Betweenness is about control of flow along shortest paths.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Degree centrality | Local popularity is what matters, and the network is too large for anything costlier. | O(V + E) |
| Closeness centrality | You want vertices that can reach everyone quickly, such as a good place for a depot or a broadcaster. | O(VE) |
| PageRank | The graph is directed and importance should flow along links, as with web pages or citations. | O(k (V + E)) |
| Sampled betweenness | The graph has millions of vertices. Running Brandes from a random sample of sources gives an unbiased estimate. | O(kE) for k sources |
| Edge betweenness | You need the score of edges rather than vertices, for example to find community boundaries with Girvan-Newman. | O(VE) |
Read the full article: Graph Centrality Measures: Degree, Betweenness, PageRank
Read the full article: Community Detection: Modularity, Louvain, Girvan-Newman
Related algorithms: PageRank, Girvan-Newman Communities, Breadth-First Search, Dijkstra's Algorithm