ArticleslgStudy

computer science

Brandes' algorithm

Brandes' algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Brandes' algorithm rather than just read about it. In short: In network theory, Brandes' algorithm is an algorithm for calculating the betweenness centrality of vertices in a graph. The algorithm was first published in 2001 by Ulrik Brandes.

Brandes' algorithm — main illustration
Brandes' algorithm — illustration

Key takeaways

  • Brandes' algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Brandes' algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Brandes' algorithm from memory before moving on to harder problems.

Reference excerpt

In network theory, Brandes' algorithm is an algorithm for calculating the betweenness centrality of vertices in a graph. The algorithm was first published in 2001 by Ulrik Brandes. Betweenness centrality, along with other measures of centrality, is an important measure in many real-world networks, such as social networks and computer networks.

Definitions There are several metrics for the centrality of a node, one such metric being the betweenness centrality. For a node v in a connected graph, the betweenness centrality is defined as:CB(v)=∑s∈V∑t∈Vσst(v)σstwhere σst is the total number of shortest paths from node s to node t, and σst(v) is the number of these paths which pass through v. For an unweighted graph, the length of a path is considered to be the number of edges it contains. By convention, σst=1 whenever s=t, since the only path is the empty path. Also, σst(v)=0 if v is either s or t, since shortest paths do not pass through their endpoints.

The quantityδst(v)=σst(v)σstis known as the pair dependency of st on v, and represents the proportion of the shortest s–t paths which travel via v. 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 v , with respect to a particular vertex s:δs(v)=∑t∈Vδst(v),with which, we can obtain the concise formulationCB(v)=∑s∈Vδs(v).

Algorithm Brandes' algorithm calculates the betweenness centrality of all nodes in a graph. For every vertex s, there are two stages.

Single-source shortest path The number of shortest paths σsv between s and every vertex v is calculated using breadth-first search. The breadth-first search starts at s, and the shortest distance d(v) of each vertex from s is recorded, dividing the graph into discrete layers. Additionally, each vertex v keeps track of the set of vertices which in the preceding layer which point to it, p(v). Described in set-builder notation, it can be written as:p(v)={u∈V∣(u,v)∈E∧d(u)+1=d(v)}.This lends itself to a simple iterative formula for σsv:σsv=∑u∈p(v)σsu,which essentially states that, if v is at depth d(v), then any shortest path at depth d(v)−1 extended by a single edge to v becomes a shortest path to v.

Backpropagation Brandes proved the following recursive formula for vertex dependencies:δs(u)=∑v∣u∈p(v)σsuσsv⋅(1+δs(v)),where the sum is taken over all vertices v that are one edge further away from s than u. This lemma eliminates the need to explicitly sum all of the pair dependencies. Using this formula, the single dependency of s on a vertex u at depth d(u) is determined by the layer at depth d(u)+1. 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 s on all other vertices u can be computed in O(|E|) 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 s, descending.

For each popped node v, we iterate over its predecessors u∈p(v): the contribution of v towards δs(u) is added, that is,σsuσsv⋅(1+δs(v)).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 s, every vertex v now contains δs(v). These can simply be added to CB(v), sinceCB(v)=∑s∈Vδs(v).After |V| iterations of single-source shortest path and backpropagation, each CB(v) contains the betweenness centrality for v.

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 |V| and the number of edges |E|. For each vertex s, we run breadth-first search, which takes O(|V|+|E|) time. Since the graph is connected, the |E| component subsumes the |V| term, since the number of edges is at least |V|−1. 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 O(|E|). The overall running time of the algorithm is therefore O(|V||E|), an improvement on the O(|V|3) time bounds achieved by prior algorithms. In addition, Brandes' algorithm improves on the space complexity of naive algorithms, which typically require O(|V|2) space. Brandes' algorithm only stores at most |E| predecessors, along with data for each vertex, making its extra space complexity O(|V|+|E|)

… excerpt ends here. Continue reading the full article.

Illustrations

Brandes' algorithm illustration

Worked examples

Example 1 — a first encounter with Brandes' algorithm

Start with the simplest possible case. Write down what Brandes' algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Brandes' algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Brandes' algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Brandes' algorithm

In research
Brandes' algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Brandes' algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Brandes' algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics 2001 in computing, Graph algorithms, Networking algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Brandes' algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Brandes' algorithm” →

How to study Brandes' algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Brandes' algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Brandes' algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Brandes' algorithm in simple terms?

In network theory, Brandes' algorithm is an algorithm for calculating the betweenness centrality of vertices in a graph. The algorithm was first published in 2001 by Ulrik Brandes.

Why does Brandes' algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Brandes' algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Brandes' algorithm.

Tags

  • 2001 in computing
  • Graph algorithms
  • Networking algorithms

Keep exploring