Skip to main content

Overview

The Weakly Connected Components (WCC) algorithm identifies groups of nodes connected through any path, disregarding edge directions. In a weakly connected component, every node is reachable from any other node when treating all edges as undirected. WCC serves as a common algorithm in scenarios such as:
  • Community detection
  • Data cleaning and preprocessing
  • Large-scale network analysis
  • Detecting isolated or loosely connected subgraphs

Algorithm Details

WCC initializes by assigning each node to its own component. It iteratively scans for edges linking nodes across different components and merges them, ignoring the directionality of edges throughout the process. The algorithm terminates when no further merges occur, producing a collection of disjoint connected components.

Performance

WCC operates with a time complexity of O(|V| + |E|), where:
  • |V| represents the total number of nodes
  • |E| represents the total number of edges This linear complexity makes WCC efficient for large graphs.

Syntax

Parameters

The procedure accepts an optional configuration Map with the following parameters:

Return Values

The procedure returns a stream of records with the following fields:

Examples

Let’s take this Social Graph as an example: Graph WCC There are 3 different communities in this graph:
  • Alice, Bob, Charlie
  • David, Emma
  • Frank

Create the Graph

Example: Find isolated communities in a social network

Expected Results

Example: Group Communities together into a single list

Expected Results

Frequently Asked Questions

Use CALL algo.WCC(null) YIELD node, componentId or pass a configuration map like CALL algo.WCC({nodeLabels: ['User']}) YIELD node, componentId.
No. WCC treats all relationships as undirected — it finds components where nodes are reachable through any path regardless of edge direction.
Run CALL algo.WCC(null) YIELD node, componentId RETURN count(DISTINCT componentId) AS numComponents.
Use WCC to find disconnected subgraphs (nodes with no path between them). Use CDLP to detect densely connected communities within a connected graph.
WCC runs in O(V + E) linear time, making it very efficient even on large graphs with millions of nodes and edges.