Guest User
Using app without sign in

Practice book
Graph Theory Through Problems300 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.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
Let the communities spread like opinions
Community detection: each vertex keeps taking the most common label among its neighbours until no label changes
Select an algorithm and generate steps to begin visualization
Label propagation is a fast way to find communities, groups of vertices linked more densely to each other than to the rest of the network. Usha Raghavan, Réka Albert and Soundar Kumara proposed it in 2007. It needs no number of communities in advance and no objective to optimise: labels simply spread between neighbours, the way an opinion spreads among friends, until every densely linked group shares one label. Each round costs time proportional to the number of edges, so it runs on networks with millions of vertices.
Every vertex starts with a label of its own. In each round the vertices, taken in a random order, adopt the label that is most common among their neighbours, counting each neighbour by the weight of the edge to it, with ties broken at random. A vertex keeps its label when it is already one of the most common. A label that dominates a dense group quickly takes over all of it, but stops at the few edges that lead out. When a whole round changes nothing, every vertex agrees with most of its neighbours and the labels are the communities. This page fixes the random seed, so the same graph always gives the same run, and scores the result by its modularity.
Label propagation finds communities in social networks, groups customers and products for recommendations, clusters web pages, detects bots and fraud rings that link to each other, and splits large graphs into pieces before heavier algorithms run. It is part of graph libraries such as NetworkX, igraph, Neo4j and Spark GraphX. Because different random orders can give different answers, it is often run several times, or used as a quick first pass before methods such as Louvain or Girvan-Newman.
Label propagation detects communities with almost no machinery. Every vertex starts with its own label, and in each round, in a random order, every vertex adopts the label most common among its neighbours, until nothing changes.
LabelPropagation(graph):
label[v] = v for every v
repeat:
changed = false
for each vertex v, in a random order:
count the labels of the neighbors of v
if label[v] is not among the most frequent:
label[v] = one of the most frequent, at random
changed = true
until not changed
return the groups of vertices with equal labelsInside a dense group a label spreads quickly, because every vertex has many neighbours that already carry it. Across a sparse boundary it has few supporters and stops. The method optimises no explicit objective. It stops when every vertex agrees with the majority of its neighbours, which is a stable state rather than an optimum.
Run label propagation on the example this page loads: three circles of friends joined by a few acquaintances. The random order and tie-breaks come from a fixed seed, so the run is the same every time it is replayed.
Example graph: Twelve vertices in three groups. A, B, C, D are all linked to each other, and so are E, F, G, H. In the third group the links are I-J, I-K, I-L, J-K, J-L and K-L. Three links join the groups: D-E, D-I and H-J. That makes 21 edges.
Label propagation finds three communities, {A, B, C, D}, {E, F, G, H} and {I, J, K, L}, with modularity 0.524, in two rounds of linear work. The labels that survive belong to B, E and K, the vertices that never had to change. A different random order could have produced different labels and, on a less clearly structured graph, a different division, which is the price paid for the speed.
Time: O(E) per round · Space: O(V)
In one round each vertex counts the labels of its neighbours, which takes time proportional to its degree, so a round costs O(V + E). The number of rounds is not bounded by a useful formula, but it is small in practice: Raghavan, Albert and Kumara reported that most vertices settle within about five rounds, even on large networks. Memory holds one label per vertex and a counter per round. This near-linear cost is why label propagation runs on graphs with hundreds of millions of edges, where modularity methods become expensive.
Label propagation is the fastest common community detection method. The others trade speed for stability or quality.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Louvain | You want communities that maximise modularity and are reproducible for a given order. Still fast on large graphs. | near O(E) per pass |
| Leiden | Like Louvain, with the guarantee that every community found is internally connected. | near O(E) per pass |
| Girvan-Newman | Small networks where a transparent, deterministic dendrogram matters more than speed. | O(E^2 V) |
| Infomap | Flow matters, for example in directed or weighted networks, and communities should trap a random walker for a long time. | near O(E) per pass |
Read the full article: Community Detection in Graphs
Read the full article: Graph Centrality Measures and PageRank
Related algorithms: Girvan-Newman Communities, Connected Components, Betweenness Centrality, Personalized PageRank