Skip to content
Part IA Lent Term

Brandes' Algorithm for Betweenness Centrality

Motivation

Computing betweenness centrality naïvely requires finding all-pairs shortest paths, which takes O(V3)O(|V|^3) with Floyd-Warshall or O(V2logV+VE)O(|V|^2 \log |V| + |V| \cdot |E|) with repeated Dijkstra. Brandes’ algorithm (2001) reduces this to O(VE)O(|V| \cdot |E|) for unweighted graphs by reusing intermediate computations across source vertices.

Key Insight

For each source vertex ss, run a single BFS (or Dijkstra for weighted graphs) to compute the shortest-path directed acyclic graph (DAG) rooted at ss. Then accumulate dependency values backwards — from the farthest nodes to the root — in a single reverse traversal. This avoids recomputing path counts for every target independently.

Algorithm Steps

Forward Pass — BFS from Each Source ss

Run BFS from ss to discover nodes in order of increasing distance. For each node vv:

  • σs[v]\sigma_s[v]: the number of distinct shortest paths from ss to vv.
    • For the source: σs[s]=1\sigma_s[s] = 1.
    • For a neighbour vv of uu: if vv is newly discovered (first time reaching it at this depth), set σs[v]=σs[u]\sigma_s[v] = \sigma_s[u] and record uu as a predecessor of vv.
    • If vv is rediscovered at the same depth (another shortest path to vv of the same length), add σs[u]\sigma_s[u] to σs[v]\sigma_s[v] and add uu to Ps(v)P_s(v) (the predecessor set).
  • Ps(v)P_s(v): the set of nodes uu such that the edge uvu \to v lies on at least one shortest path from ss to vv.

The result is a shortest-path DAG: edges only go from nodes at distance dd to nodes at distance d+1d+1.

Backward Pass — Accumulate Dependencies

Process nodes in reverse BFS order (farthest from ss first, closest last). For each node vv (excluding ss):

δs(v)=w  :  vPs(w)σs[v]σs[w](1+δs(w))\delta_s(v) = \sum_{w \;:\; v \in P_s(w)} \frac{\sigma_s[v]}{\sigma_s[w]} \cdot \big(1 + \delta_s(w)\big)

This says: vv‘s dependency contribution to paths ending at ww is proportional to the fraction of shortest paths from ss to ww that pass through vv, plus the dependency that ww itself accumulates from nodes beyond it.

Add δs(v)\delta_s(v) to CB(v)C_B(v).

Undirected Correction

For undirected graphs, each unordered pair (s,t)(s, t) appears twice in the summation (once as (s,t)(s, t) and once as (t,s)(t, s)). After summing over all sources ss, halve all betweenness scores.

Complexity

Graph TypeAlgorithm UsedTime Complexity
UnweightedBFS from each sourceO(VE)O(\lvert V \rvert \cdot \lvert E \rvert)
WeightedDijkstra from each sourceO(VE+V2logV)O(\lvert V \rvert \cdot \lvert E \rvert + \lvert V \rvert^2 \log \lvert V \rvert)

This is close to optimal for dense graphs: all-pairs shortest paths inherently requires examining all edges from all sources, which is Ω(VE)\Omega(|V| \cdot |E|) in the worst case.

What the Exam Expects

The full dependency-accumulation formula is beyond the scope of most MLRD exam questions. What you should know:

  1. Brandes runs BFS (or Dijkstra) from every source node, giving O(VE)O(|V| \cdot |E|) total time.
  2. The forward pass computes shortest-path DAGs and σ\sigma counts (number of shortest paths to each node).
  3. The backward pass accumulates dependencies from farthest nodes backward to the root.
  4. For undirected graphs, halve the final betweenness scores.
  5. This algorithm is used in practice to compute edge betweenness for Newman-Girvan community detection: edge betweenness is computed by summing the dependency contributions that flow through each edge during the backward pass.

Connection to Newman-Girvan

Newman-Girvan repeatedly removes edges with highest betweenness. Computing edge betweenness for all edges naïvely after each removal would be extremely expensive. Brandes makes this feasible: after each edge removal, recompute all-pairs shortest paths in O(VE)O(|V| \cdot |E|). The algorithm is run repeatedly until the desired number of clusters is reached.

Summary

StepOperation
Overall approachBFS/Dijkstra from every source, accumulate dependencies backward
Forward passCompute σs[v]\sigma_s[v] (path counts) and predecessors Ps(v)P_s(v)
Backward passAccumulate δs(v)\delta_s(v) from farthest nodes to source
Complexity (unweighted)O(VE)O(\lvert V \rvert \cdot \lvert E \rvert)
Complexity (weighted)O(VE+V2logV)O(\lvert V \rvert \cdot \lvert E \rvert + \lvert V \rvert^2 \log \lvert V \rvert)
Undirected correctionHalve all final betweenness scores

Past paper questions: y2025p3q8 (Newman-Girvan context)