learngraphtheory.org

Guest User

Using app without sign in

Cover of the book Graph Theory Through Problems

Practice book

Graph Theory Through Problems

300 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.

Available inKindlePaperback

13 chapters

Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on Amazon
Algorithm Selection

Select an algorithm and generate steps to begin visualization

Girvan-Newman Calculator

Find communities by cutting the busiest edges

Community detection: delete the edge with the highest betweenness until the graph splits, keep the division with the best modularity

Time: O(E²V)
Space: O(V + E)
Use Case: Social circles, biological modules, citation clusters
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Girvan-Newman Communities

The Girvan-Newman algorithm detects communities in a network: groups of vertices with many edges inside and few between them. Michelle Girvan and Mark Newman published it in 2002, and it was one of the first methods to find communities by removing edges rather than by building groups up. It produces a whole hierarchy of divisions, from one community down to single vertices.

How it works

The edges between communities are the ones that many shortest paths have to use, so their edge betweenness is high. The algorithm computes the betweenness of every edge with Brandes' algorithm, deletes the edge with the highest value, recomputes, and repeats. As edges disappear, the graph falls apart into ever smaller connected pieces. Each division is scored by modularity Q: the fraction of edges inside the communities minus the fraction expected if the edges were wired at random with the same degrees. The division with the highest Q is the answer; values above about 0.3 suggest real community structure. Recomputing after every deletion makes the method O(E²V).

Applications

Community detection finds friend groups and interest clusters in social networks, research fields in citation networks, functional modules in protein and gene networks, and related products in purchase data. Girvan-Newman is mostly used on small and medium networks and in teaching, because it is easy to follow and shows the full hierarchy, while faster methods such as Louvain handle very large graphs.

Pseudocode

Girvan-Newman finds communities by removing edges rather than grouping vertices. The edges between communities carry the most shortest paths, so deleting the edge of highest betweenness again and again pulls the groups apart.

GirvanNewman(graph):
    best = the whole graph as one community,  Q = 0
    while the graph has edges:
        compute the betweenness of every edge     // Brandes
        delete the edge with the highest betweenness
        if the number of components increased:
            Q = modularity of the components, on the original graph
            if Q > Q(best): best = the components
    return best

The edge betweenness must be recomputed after every deletion, because removing a bridge between two groups reroutes all the shortest paths that used it, often onto another bridge. The method produces a whole hierarchy of splits, a dendrogram, and modularity is the yardstick used to choose one level of it.

Worked example, step by step

Divide the twelve-vertex network of the example this page loads. It has three tightly knit groups of four, joined by only three edges.

Example graph: Undirected edges within the groups: A-B, A-C, A-D, B-C, B-D, C-D, then E-F, E-G, E-H, F-G, F-H, G-H, then I-J, I-K, J-K, J-L, K-L. Between the groups: D-E, D-I and H-J. That makes 20 edges.

  1. First deletion. The highest edge betweenness belongs to D-E, with 18.5: all 16 pairs between the first two groups use it, plus shares of the paths from the second group to the third. It is deleted, but the graph is still connected.
  2. Recompute and delete D-I. With D-E gone, every path from {A, B, C, D} to the other eight vertices must use D-I, so its betweenness jumps to 4 × 8 = 32. Deleting it splits off the first group. Modularity Q = 0.355.
  3. Delete H-J. The only link left between the other two groups is H-J, with betweenness 4 × 4 = 16. Deleting it gives three communities, {A, B, C, D}, {E, F, G, H} and {I, J, K, L}, with Q = 0.515, the best value of the whole run.
  4. Keep dismantling. Next go I-J, then I-K, which isolates I, and Q drops to 0.449. The algorithm continues until every vertex stands alone, with Q falling to -0.088, and simply remembers the best division it passed.

The best division has three communities and modularity 0.515, which can be checked by hand: each group of four contributes its share of internal edges, 6, 6 and 5 out of 20, minus the square of its share of the degree sum, 14, 14 and 12 out of 40. The answer matches the visible structure exactly. The price is speed: every deletion needs a fresh edge betweenness computation, three to reach this division and twenty for the full run.

Complexity, and where it comes from

Time: O(E^2 V) · Space: O(V + E)

Each round runs Brandes' algorithm for edge betweenness in O(VE) on an unweighted graph, and there are up to E rounds, one per deleted edge. The total is O(E^2 V), which is O(V^3) on sparse graphs where E is proportional to V. Recomputation can be restricted to the component that lost an edge, which helps in practice but does not change the worst case. In practice this limits Girvan-Newman to networks of a few thousand vertices, which is why faster modularity heuristics replaced it for large data.

When to use Girvan-Newman Communities, and when not to

Girvan-Newman is the classical divisive method and is still valued for its transparency. For large networks other methods are used.

AlternativePrefer it whenCost
LouvainLarge networks where modularity is the objective. It merges vertices greedily and then aggregates, and it is the default in most tools.near O(E) per pass
LeidenLike Louvain, but it guarantees that every community found is internally connected.near O(E) per pass
Label propagationSpeed matters most and some run-to-run variation is acceptable. No objective function at all.O(E) per round
Spectral clusteringYou know the number of communities in advance and the graph fits in memory as a matrix.O(V^3) dense

Common pitfalls

  • Computing betweenness only once. Ranking all edges by their initial betweenness and deleting them in that order is much faster but wrong. In the example D-I only becomes the obvious bridge after D-E is gone, and its score nearly doubles.
  • Stopping at the first split. The first split here gives two communities and Q = 0.355, while the best division has three. Continue the process and choose the level with the highest modularity.
  • Computing modularity on the damaged graph. Modularity must be evaluated with the edges and degrees of the original graph. Using the graph after deletions rewards splits that the algorithm itself created.
  • Trusting modularity on small communities. Modularity has a resolution limit: in large networks it can merge small, genuinely separate communities. If the communities you expect are small, inspect the dendrogram rather than just its best level.

Frequently asked questions

What is the Girvan-Newman algorithm?
It is a divisive community detection method, published by Michelle Girvan and Mark Newman in 2002. It repeatedly deletes the edge with the highest edge betweenness and recomputes the betweenness, so the network breaks apart along the links between communities.
Why does Girvan-Newman remove edges with high betweenness?
Edges between communities are few, so the shortest paths between members of different groups must squeeze through them. They therefore carry many more shortest paths than edges inside a dense group, and removing them separates the groups.
What is modularity?
Modularity Q compares the fraction of edges inside the communities with the fraction expected if edges were placed at random with the same degrees. It ranges up to 1. Values above about 0.3 usually indicate real community structure.
What is the time complexity of Girvan-Newman?
O(E^2 V) for unweighted graphs, because each of up to E edge deletions is followed by an O(VE) betweenness computation. That is O(V^3) on sparse graphs, practical only up to a few thousand vertices.
What is the difference between Girvan-Newman and Louvain?
Girvan-Newman is divisive: it removes edges from the whole graph until it falls apart. Louvain is agglomerative: it starts with every vertex alone and merges groups to increase modularity. Louvain is far faster and handles millions of vertices, while Girvan-Newman is slower but easy to explain.

Related algorithms: Betweenness Centrality, K-Means Logistics Clustering, Bridge Finding, Tarjan's SCC Algorithm

Interactive Controls

Zoom Controls

39%
Nodes: 12
Edges: 20