Skip to content
Graph Intelligence Hub
Menu

Algorithm

Weakly connected components

activeNeeds verification

Finds groups of nodes connected when edge direction is ignored; often the first data-quality check on a new graph.

Intuition

Flood-fill from each unvisited node (BFS/DFS) or merge endpoints with union–find; every flood is one component.

Complexity

TimeO(V + E)
SpaceO(V)

Python

import networkx as nx
comps = list(nx.weakly_connected_components(DG))

Cypher (Neo4j GDS)

CALL gds.wcc.stream('myGraph')
YIELD nodeId, componentId RETURN componentId, 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(V + E)
Space complexityO(V)

Relationships

Applied to
Prerequisites
Implemented by