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

Label Propagation Calculator

Let the communities spread like opinions

Community detection: each vertex keeps taking the most common label among its neighbours until no label changes

Time: O(E) per round
Space: O(V)
Use Case: Social network communities, fraud rings, graph partitioning
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Label Propagation

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.

How it works

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.

Applications

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.

Pseudocode

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 labels

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

Worked example, step by step

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.

  1. Start. Twelve vertices, twelve labels. The round 1 order begins F, L, D.
  2. First choices are ties. F sees the labels E, G and H once each and picks E at random. L picks K from a three-way tie. D has five different neighbour labels, A, B, C, E and I, and picks B.
  3. Majorities form. J now sees K twice, through K and L, and takes K. H sees E twice, through E and F, and takes E. C sees B twice and takes B. A then sees B three times.
  4. End of round 1. I takes K with three votes against one, and G takes E with three votes. Nine vertices have changed, and only three labels remain: B, E and K.
  5. Round 2. No vertex changes. Every vertex already carries one of the most frequent labels among its neighbours, so the algorithm stops.

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.

Complexity, and where it comes from

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.

When to use Label Propagation, and when not to

Label propagation is the fastest common community detection method. The others trade speed for stability or quality.

AlternativePrefer it whenCost
LouvainYou want communities that maximise modularity and are reproducible for a given order. Still fast on large graphs.near O(E) per pass
LeidenLike Louvain, with the guarantee that every community found is internally connected.near O(E) per pass
Girvan-NewmanSmall networks where a transparent, deterministic dendrogram matters more than speed.O(E^2 V)
InfomapFlow matters, for example in directed or weighted networks, and communities should trap a random walker for a long time.near O(E) per pass

Common pitfalls

  • Updating all labels at once. With synchronous updates, where every vertex reads the labels of the previous round, labels can flip back and forth forever, for example on bipartite parts of the graph. Update asynchronously, in a random order, as the pseudocode does.
  • Treating one run as the answer. Different random orders can give different communities. Run it several times and keep the division that recurs most often, or the one with the highest modularity.
  • A single giant community. On graphs without clear structure, one label can sweep across most of the network. If the result is one huge community, the graph may simply not have strong communities, or a method with a resolution parameter is needed.
  • Stopping when nothing changed in the order checked. The correct test is that every vertex holds one of the most frequent labels among its neighbours. Stopping early because a partial pass changed nothing can leave unstable vertices.

Frequently asked questions

What is the label propagation algorithm?
It is a community detection method, introduced by Raghavan, Albert and Kumara in 2007, in which each vertex starts with a unique label and repeatedly adopts the label that is most frequent among its neighbours. Densely connected groups converge on a common label, which defines a community.
How fast is label propagation?
Each round costs O(V + E), and only a handful of rounds are usually needed, so the whole run is close to linear in the number of edges. It is one of the few community detection methods that scale to graphs with billions of edges.
Why does label propagation give different results on different runs?
The order in which vertices update and the way ties between equally frequent labels are broken are random. Different choices can lead to different stable states, especially on graphs whose community structure is weak.
What is the difference between label propagation and Louvain?
Label propagation has no objective function: it stops when every vertex agrees with its neighbours. Louvain explicitly maximises modularity by moving vertices and aggregating communities. Louvain is usually more stable and accurate, label propagation is simpler and faster.
Can label propagation use known labels?
Yes. In semi-supervised learning, a few vertices keep fixed labels, for example known spam accounts, and the others propagate them. This is the original use of the idea in machine learning, by Zhu and Ghahramani, before it was applied to community detection.

Related algorithms: Girvan-Newman Communities, Connected Components, Betweenness Centrality, Personalized PageRank

Interactive Controls

Zoom Controls

39%
Nodes: 12
Edges: 21