# What algorithm is igraph using to calculate betweenness centrality?

**URL:** <https://igraph.discourse.group/t/what-algorithm-is-igraph-using-to-calculate-betweenness-centrality/900>\
**Category:** Development\
**Tags:** C, Python\
**Created:** [15 October 2021 15:56 UTC](https://igraph.discourse.group/t/what-algorithm-is-igraph-using-to-calculate-betweenness-centrality/900 "2021-10-15T15:56:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alyssa](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/alyssa/32/590_2.png) [@alyssa](https://igraph.discourse.group/u/alyssa)\
**Post date:** [15 October 2021 15:56 UTC](https://igraph.discourse.group/t/what-algorithm-is-igraph-using-to-calculate-betweenness-centrality/900/1 "2021-10-15T15:56:51Z")

</div>

Hi! I am using igraph (Python) to calculate betweenness centrality and was surprised by how fast it was – the betweeness centrality calculation for ~40k nodes and ~50k edges takes about 3 minutes, while it never finishes when I try to use networkx. I’m curious what algorithm igraph uses, and how is it so much faster?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [15 October 2021 21:44 UTC](https://igraph.discourse.group/t/what-algorithm-is-igraph-using-to-calculate-betweenness-centrality/900/2 "2021-10-15T21:44:46Z")

</div>

This is likely not about the algorithm, but about Python simply being much, much slower than compiled languages such as C.

igraph uses Brandes’s algorithm, which is standard for calculating betweenness.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [15 October 2021 22:01 UTC](https://igraph.discourse.group/t/what-algorithm-is-igraph-using-to-calculate-betweenness-centrality/900/3 "2021-10-15T22:01:22Z")

</div>

For completeness, betweenness calculation is implemented here:

> <https://github.com/igraph/igraph/blob/master/src/centrality/betweenness.c>

@alyssa: If you like, you are welcome to submit a pull request that includes a reference to Brandes’s paper in the documentation. It’s probably good to mention it there.
