In
network theory
In mathematics, computer science, and network science, network theory is a part of graph theory. It defines networks as Graph (discrete mathematics), graphs where the vertices or edges possess attributes. Network theory analyses these networks ...
, Brandes' algorithm is an
algorithm
In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
for calculating the
betweenness centrality
In graph theory, betweenness centrality is a measure of centrality in a graph based on shortest paths. For every pair of vertices in a connected graph, there exists at least one shortest path between the vertices, that is, there exists at leas ...
of
vertices in a
graph
Graph may refer to:
Mathematics
*Graph (discrete mathematics), a structure made of vertices and edges
**Graph theory, the study of such graphs and their properties
*Graph (topology), a topological space resembling a graph in the sense of discret ...
. The algorithm was first published in 2001 by
Ulrik Brandes.
Betweenness centrality, along with other measures of
centrality
In graph theory and network analysis, indicators of centrality assign numbers or rankings to nodes within a graph corresponding to their network position. Applications include identifying the most influential person(s) in a social network, ke ...
, is an important measure in many real-world networks, such as
social networks
A social network is a social structure consisting of a set of social actors (such as individuals or organizations), networks of dyadic ties, and other social interactions between actors. The social network perspective provides a set of meth ...
and
computer networks
A computer network is a collection of communicating computers and other devices, such as printers and smart phones. In order to communicate, the computers and devices must be connected by wired media like copper cables, optical fibers, or ...
.
Definitions
There are several metrics for the
centrality
In graph theory and network analysis, indicators of centrality assign numbers or rankings to nodes within a graph corresponding to their network position. Applications include identifying the most influential person(s) in a social network, ke ...
of a node, one such metric being the ''betweenness centrality''.
For a node
in a
connected graph
In mathematics and computer science, connectivity is one of the basic concepts of graph theory: it asks for the minimum number of elements (nodes or edges) that need to be removed to separate the remaining nodes into two or more isolated subgrap ...
, the betweenness centrality is defined as:
where
is the total number of shortest paths from node
to node
, and
is the number of these paths which pass through
. For an unweighted graph, the length of a path is considered to be the number of edges it contains.
By convention,
whenever
, since the only path is the empty path. Also,
if
is either
or
, since shortest paths do not pass ''through'' their endpoints.
The quantity
is known as the ''pair dependency'' of
on
, and represents the proportion of the shortest
–
paths which travel via
. The betweenness centrality is simply the sum of the pair dependencies over all pairs.
As well as the pair dependency, it is also useful to define the (''single) dependency'' on
, with respect to a particular vertex
:
,
with which, we can obtain the concise formulation
.
Algorithm
Brandes' algorithm calculates the betweenness centrality of all nodes in a graph. For every vertex
, there are two stages.
Single-source shortest path
The number of shortest paths
between
and every vertex
is calculated using
breadth-first search
Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next dept ...
. The breadth-first search starts at
, and the shortest distance
of each vertex from
is recorded, dividing the graph into discrete layers. Additionally, each vertex
keeps track of the set of vertices which in the preceding layer which point to it,
. Described in
set-builder notation
In mathematics and more specifically in set theory, set-builder notation is a notation for specifying a set by a property that characterizes its members.
Specifying sets by member properties is allowed by the axiom schema of specification. Th ...
, it can be written as:
.
This lends itself to a simple iterative formula for
:
,
which essentially states that, if
is at depth
, then any shortest path at depth
extended by a single edge to
becomes a shortest path to
.
Backpropagation
Brandes proved the following recursive formula for vertex dependencies:
,
where the sum is taken over all vertices
that are one edge further away from
than
. This lemma eliminates the need to explicitly sum all of the pair dependencies. Using this formula, the single dependency of
on a vertex
at depth
is determined by the layer at depth
. Furthermore, the order of summation is irrelevant, which allows for a bottom up approach starting at the deepest layer.
It turns out that the dependencies of
on all other vertices
can be computed in
time. During the breadth-first search, the order in which vertices are visited is logged in a
stack data structure. The backpropagation step then repeatedly pops off vertices, which are naturally sorted by their distance from
, descending.
For each popped node
, we iterate over its predecessors
: the contribution of
towards
is added, that is,
.
Crucially, every layer propagates its dependencies completely, before moving to the layer with lower depth, due to the nature of breadth-first search. Once the propagation reaches back to
, every vertex
now contains
. These can simply be added to
, since
.
After
iterations of ''single-source shortest path'' and ''backpropagation'', each
contains the betweenness centrality for
.
Pseudocode
The following pseudocode illustrates Brandes' algorithm on an unweighted directed graph.
algorithm Brandes(''Graph'') is
for each ''u'' in ''Graph.Vertices'' do
CB
'u''← 0
for each ''s'' in ''Graph.Vertices'' do
for each ''v'' in ''Graph.Vertices'' do
δ
'v''← 0 // Single dependency of s on v
prev
'v''← empty list // Immediate predecessors of v during BFS
σ
'v''← 0 // Number of shortest paths from s to v (s implied)
dist
'v''← ''null'' // No paths are known initially,
σ
's''← 1 // except the start vertex
dist
's''← 0
''Q'' ← queue containing only ''s'' // Breadth-first search
''S'' ← empty stack // Record the order in which vertices are visited
// ''Single-source shortest paths''
while ''Q'' is not empty do
''u'' ← ''Q''.dequeue()
''S''.push(''u'')
for each ''v'' in ''Graph.Neighbours''
'u''''do''
if dist
'v''= ''null'' then
dist
'v''← dist
'u''+ 1
''Q''.enqueue(''v'')
if dist
'v''= dist
'u''+ 1 then
σ
'v''← σ
'v''+ σ
'u'' prev
'v''append(''u'')
// ''Backpropagation of dependencies''
while ''S'' is not empty do
''v'' ← ''S''.pop()
for each ''u'' in prev
'v''do
δ
'u''← δ
'u''+ σ
'u''/ σ
'v''* (1 + δ
'v''
if ''v'' ≠ ''s'' then
CB
'v''← CB
'v''+ δ
'v'' // Halved for undirected graphs
return CB
Running time
The running time of the algorithm is expressed in terms of the number of vertices
and the number of edges
.
For each vertex
, we run breadth-first search, which takes
time. Since the graph is connected, the
component subsumes the
term, since the number of edges is at least
.
In the backpropagation stage, every vertex is popped off the stack, and its predecessors are iterated over. However, since each predecessor entry corresponds to an edge in the graph, this stage is also bounded by
.
The overall running time of the algorithm is therefore
, an improvement on the
time bounds achieved by prior algorithms.
In addition, Brandes' algorithm improves on the space complexity of naive algorithms, which typically require
space. Brandes' algorithm only stores at most
predecessors, along with data for each vertex, making its extra space complexity
Variants
The algorithm can be generalised to weighted graphs by using
Dijkstra's algorithm
Dijkstra's algorithm ( ) is an algorithm for finding the shortest paths between nodes in a weighted graph, which may represent, for example, a road network. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three ...
instead of breadth-first search. When operating on undirected graphs, the betweenness centrality may be divided by 2, to avoid double counting each path's reversed counterpart. Variants also exist to calculate different measures of centrality, including ''betweenness'' with paths at most length
, ''edge betweenness'', ''load betweenness'', and ''stress betweenness''.
References
{{reflist
Graph algorithms
Networking algorithms
Articles with example pseudocode
2001 in computing