Community Detection
algo.wcc
| Property | Value |
|---|---|
Procedure |
|
Category |
Community Detection |
Complexity |
CPU |
Min Args |
0 |
Max Args |
1 |
Syntax
CALL algo.wcc([relTypes])
YIELD node, componentId
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
String |
No |
all types |
Comma-separated relationship types |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
RID |
Vertex identity |
|
Integer |
Sequential component identifier (0-based) |
Description
Identifies weakly connected components using BFS, treating all edges as undirected regardless of their actual direction. Two vertices are in the same component if there exists any undirected path between them. Component IDs are remapped to sequential integers starting at 0.
Use Cases
-
Data quality: detecting isolated subgraphs
-
Network partition detection
-
Graph reachability analysis
Example
CALL algo.wcc('CONNECTED_TO')
YIELD node, componentId
RETURN componentId, count(node) AS size ORDER BY size DESC
References
algo.scc
| Property | Value |
|---|---|
Procedure |
|
Category |
Community Detection |
Complexity |
CPU |
Min Args |
0 |
Max Args |
1 |
Syntax
CALL algo.scc([relTypes])
YIELD node, componentId
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
String |
No |
all types |
Comma-separated relationship types |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
RID |
Vertex identity |
|
Integer |
Sequential component identifier (0-based) |
Description
Identifies strongly connected components using Kosaraju’s two-pass algorithm: iterative DFS on the original graph to compute finish-time ordering, then BFS on the reversed graph in reverse finish order. A strongly connected component is a maximal set of vertices where every vertex is reachable from every other.
Use Cases
-
Deadlock detection in dependency graphs
-
Circular dependency analysis in software systems
-
Identifying mutually-reachable clusters in directed networks
Example
CALL algo.scc('DEPENDS_ON')
YIELD node, componentId
RETURN componentId, collect(node) AS members ORDER BY size(members) DESC
References
algo.louvain
| Property | Value |
|---|---|
Procedure |
|
Category |
Community Detection |
Complexity |
CPU |
Min Args |
0 |
Max Args |
1 |
Syntax
CALL algo.louvain([{maxIterations: 10, tolerance: 0.0001, weightProperty: null}])
YIELD node, communityId, modularity
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
config map |
Map |
No |
see defaults |
Configuration properties (all optional) |
|
Integer |
No |
|
Maximum number of phase-1 passes |
|
Double |
No |
|
Stop when modularity gain falls below this value |
|
String |
No |
|
Edge property for weighted modularity |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
RID |
Vertex identity |
|
Integer |
Sequential community identifier (0-based) |
|
Double |
Final modularity score of the partition |
Description
Detects communities by maximizing modularity using the Louvain method: a greedy phase where each node is moved to the neighboring community that maximally increases modularity, iterated until no improvement is found. Community IDs are remapped to sequential 0-based integers.
Use Cases
-
Social community discovery
-
Topic clustering in citation networks
-
Customer segmentation in purchase graphs
Example
CALL algo.louvain({maxIterations: 15, weightProperty: 'weight'})
YIELD node, communityId, modularity
RETURN communityId, collect(node) AS members, modularity ORDER BY size(members) DESC
References
algo.leiden
| Property | Value |
|---|---|
Procedure |
|
Category |
Community Detection |
Complexity |
CPU |
Min Args |
0 |
Max Args |
3 |
Syntax
CALL algo.leiden([relTypes, maxIterations, resolution])
YIELD nodeId, community
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
String |
No |
all types |
Comma-separated relationship types |
|
Integer |
No |
|
Maximum number of local-move + refinement iterations |
|
Double |
No |
|
Resolution parameter γ (higher = more, smaller communities) |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
RID |
Vertex identity |
|
Integer |
Sequential community identifier (0-based) |
Description
An improved community detection algorithm over Louvain, featuring a two-phase approach: (1) local greedy moves maximizing modularity, followed by (2) a refinement phase that checks whether nodes should be split out from their community to ensure well-connectedness. The resolution parameter γ controls granularity of the resulting communities.
Use Cases
-
High-quality community detection with guaranteed well-connectedness
-
Hierarchical community structure analysis
-
Fine-grained cluster control via resolution parameter
Example
CALL algo.leiden('KNOWS', 10, 1.0)
YIELD nodeId, community
RETURN community, count(nodeId) AS size ORDER BY size DESC
References
-
Traag, V. A., Waltman, L., & van Eck, N. J. (2019). From Louvain to Leiden: guaranteeing well-connected communities. Scientific Reports, 9, 5233.
algo.labelpropagation
| Property | Value |
|---|---|
Procedure |
|
Category |
Community Detection |
Complexity |
CPU |
Min Args |
0 |
Max Args |
1 |
Syntax
CALL algo.labelpropagation([{maxIterations: 10, direction: 'BOTH'}])
YIELD node, communityId
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
config map |
Map |
No |
see defaults |
Configuration properties (all optional) |
|
Integer |
No |
|
Maximum number of propagation passes |
|
String |
No |
|
Edge direction to follow: |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
RID |
Vertex identity |
|
Integer |
Community label assigned to this vertex |
Description
Detects communities by iteratively propagating labels. Each vertex adopts the most frequent label among its neighbors; ties are broken by choosing the smallest label. Vertex processing order is randomly shuffled each iteration. Converges quickly in practice but may produce non-deterministic results.
Use Cases
-
Fast community detection in very large graphs
-
Semi-supervised classification when some labels are pre-assigned
-
Near-linear time community discovery
Example
CALL algo.labelpropagation({maxIterations: 20, direction: 'OUT'})
YIELD node, communityId
RETURN communityId, count(node) AS size ORDER BY size DESC
References
algo.hierarchicalClustering
| Property | Value |
|---|---|
Procedure |
|
Category |
Community Detection |
Complexity |
CPU+RAM |
Min Args |
0 |
Max Args |
2 |
Syntax
CALL algo.hierarchicalClustering([relTypes, numClusters])
YIELD nodeId, cluster
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
|
String |
No |
all types |
Comma-separated relationship types |
|
Integer |
No |
|
Desired number of clusters |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
RID |
Vertex identity |
|
Integer |
Assigned cluster identifier |
Description
Performs agglomerative (bottom-up) hierarchical clustering using single-linkage: each vertex starts in its own cluster, and the two clusters with the highest Jaccard similarity between their neighbor sets are merged iteratively until the target number of clusters is reached. Uses Union-Find for efficient cluster management.
Use Cases
-
Dendrogram-style cluster analysis
-
Grouping vertices by structural neighborhood similarity
-
Coarse-grained community assignment with controlled count
Example
CALL algo.hierarchicalClustering('SIMILAR_TO', 5)
YIELD nodeId, cluster
RETURN cluster, count(nodeId) AS size ORDER BY size DESC
References
algo.slpa
| Property | Value |
|---|---|
Procedure |
|
Category |
Community Detection |
Complexity |
CPU |
Min Args |
0 |
Max Args |
1 |
Syntax
CALL algo.slpa([config]) YIELD node, communities
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
Map |
|
Configuration map (see below) |
Config Parameters
| Key | Type | Default | Description |
|---|---|---|---|
|
Integer |
|
Number of propagation iterations (T) |
|
Float |
|
Minimum label frequency in memory to be included in output |
|
Long |
|
Random seed for reproducibility; |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
Vertex |
The vertex |
|
List<Long> |
List of community IDs the vertex belongs to (overlapping) |
Description
SLPA (Speaker-Listener Label Propagation Algorithm) detects overlapping communities. Each node maintains a memory of labels it has received over T iterations. In each iteration every node acts as a speaker (emitting its most frequent memory label) and a listener (recording the most common label from its neighbours). After T rounds, labels appearing with frequency ≥ threshold are retained as community assignments.
Unlike non-overlapping algorithms (Louvain, Label Propagation), SLPA allows each vertex to belong to multiple communities simultaneously, making it suitable for social networks where individuals naturally participate in multiple groups.
Use Cases
-
Overlapping community detection in social networks
-
Finding cross-cutting roles in collaboration networks
-
Identifying nodes that bridge multiple communities
Example
CALL algo.slpa({iterations: 20, threshold: 0.1, seed: 42})
YIELD node, communities
RETURN node.name AS name, communities
ORDER BY size(communities) DESC
References
algo.maxKCut
| Property | Value |
|---|---|
Procedure |
|
Category |
Community Detection |
Complexity |
CPU |
Min Args |
1 |
Max Args |
2 |
Syntax
CALL algo.maxKCut(k [, config]) YIELD node, community, cutWeight
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
Integer |
— |
Number of partitions (≥ 2) |
|
Map |
|
Configuration map (see below) |
Config Parameters
| Key | Type | Default | Description |
|---|---|---|---|
|
Integer |
|
Maximum local-search passes per restart |
|
Integer |
|
Number of random restarts (best result returned) |
|
String |
|
Edge property for weights; |
|
String |
all types |
Comma-separated edge type names |
|
String |
|
Edge traversal direction: |
|
Long |
|
Random seed; -1 = random |
Yield Fields
| Field | Type | Description |
|---|---|---|
|
Vertex |
The vertex |
|
Integer |
Partition index in range [0, k − 1] |
|
Float |
Total weight of inter-partition edges (same on every row) |
Description
Approximates the Maximum k-Cut problem: partition all vertices into k disjoint subsets to maximise the total weight of edges that cross between different partitions. Uses a greedy local-search heuristic:
-
Randomly assign each vertex to one of k partitions.
-
For each vertex, compute the cut gain for every possible partition and move it to the best one.
-
Repeat until no vertex can be moved to improve the cut (or
maxIterationsis reached). -
Repeat steps 1–3 for
restartsindependent runs and return the best result found.
This heuristic achieves a (k−1)/k fraction of the optimal cut on unweighted graphs and converges quickly in practice.
Use Cases
-
Graph partitioning for parallel processing
-
Community detection via balanced cut
-
Circuit bipartitioning and VLSI placement
Example
CALL algo.maxKCut(3, {restarts: 5, seed: 42})
YIELD node, community, cutWeight
RETURN node.name AS name, community
ORDER BY community
References
-
Sahni, S. & Gonzalez, T. (1976). P-Complete Approximation Problems. Journal of the ACM.