Skip to content
Graph Intelligence Hub
Menu

Algorithm

Label propagation

activeNeeds verification

Near-linear community detection where each node repeatedly adopts the label most common among its neighbours until labels stabilise.

Intuition

Start with every node in its own group; nodes copy the majority label of their neighbours, so dense groups converge on one label.

Pseudocode

label[v] = v for all v
repeat until no label changes:
  for v in random order:
    label[v] = most frequent label among neighbours(v)

Complexity

TimeO(E) per iteration
SpaceO(V)

Python

import networkx as nx
comms = nx.community.label_propagation_communities(G)

Cypher (Neo4j GDS)

CALL gds.labelPropagation.stream('myGraph')
YIELD nodeId, communityId RETURN communityId, count(*) AS size

Procedure names and options vary between GDS versions; check the GDS docs for your version.

An interactive step-by-step visualizer for this algorithm is planned for phase 3.

Profile

Time complexityO(E) per iteration
Space complexityO(V)

Relationships

Implemented by