UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Eccentricity Centrality
    • Betweenness Centrality
    • Bridges
    • Articulation Points
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • KNN
    • Vector Similarity
    • Bipartite Graph
    • HyperANF
    • Weakly Connected Components (WCC)
    • Strongly Connected Components (SCC)
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Triangle Count
    • Clique Count
    • k-Core
    • k-Truss
    • p-Cohesion
    • Induced Subgraph
    • Topological Sort
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Dijkstra's Shortest Path
    • A* Shortest Path
    • Yen's K-Shortest Paths
    • Shortest Path (BFS)
    • Delta-Stepping SSSP
    • Shortest Path Faster Algorithm (SPFA)
    • All-Pairs Shortest Path (APSP)
    • Minimum Spanning Tree (MST)
    • K-Spanning Tree
    • Steiner Tree
    • Prize-Collecting Steiner Tree (PCST)
    • Minimum Cost Flow
    • Maximum Flow
    • K-Hop Fast
    • Longest Path (DAG)
    • Random Walk
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Same Community
    • Louvain
    • Leiden
    • Modularity Optimization
    • Label Propagation
    • HANP
    • SLPA
    • k-Means
    • HDBSCAN
    • K-1 Coloring
    • Modularity
    • Conductance
    • Max k-Cut
      • Node2Vec
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Algorithms
  4. /
  5. Graph Structure

Weakly Connected Components (WCC)

Overview

The WCC algorithm identifies the weakly connected components in a graph. A weakly connected component is a maximal subset of nodes where a path exists between any pair of nodes when edge directions are ignored.

The number of connected components serves as a coarse-grained measure of graph connectivity. If the number remains unchanged after modifications to the graph, it suggests that the macroscopic connectivity has not been altered significantly.

Concepts

Connected Component

A connected component is a maximal subset of nodes in a graph where all nodes in that subset are reachable from one another by following edges. A maximal subset means that no additional nodes can be added to the subset without breaking the connectivity requirement.

Weakly vs Strongly Connected Components

  • A weakly connected component (WCC) is a subset of nodes where a path exists between any pair of nodes when edge directions are ignored.
  • A strongly connected component (SCC) is a subset of nodes in a directed graph where there is a directed path between every pair of nodes in both directions. See SCC for details.

This example shows the 3 strongly connected components and 2 weakly connected components of a graph.

Considerations

  • The algorithm treats all edges as undirected.
  • Each isolated node constitutes its own connected component.

Example Graph

GQL
INSERT (Mike:member {_id: "Mike"}), (Cathy:member {_id: "Cathy"}),
       (Anna:member {_id: "Anna"}), (Joe:member {_id: "Joe"}),
       (Sam:member {_id: "Sam"}), (Bob:member {_id: "Bob"}),
       (Bill:member {_id: "Bill"}), (Alice:member {_id: "Alice"}),
       (Cathy)-[:helps]->(Mike), (Anna)-[:helps]->(Sam),
       (Anna)-[:helps]->(Joe), (Joe)-[:helps]->(Bob),
       (Bob)-[:helps]->(Joe), (Bob)-[:helps]->(Bill),
       (Bill)-[:helps]->(Alice), (Bill)-[:helps]->(Anna),
       (Alice)-[:helps]->(Anna)

Run Mode

Returns:

ColumnTypeDescription
nodeIdSTRINGNode identifier (_id)
componentIdINTComponent identifier
componentSizeINTNumber of nodes in component
GQL
CALL algo.wcc() YIELD nodeId, componentId, componentSize

Result:

nodeIdcomponentIdcomponentSize
Mike02
Cathy02
Bill16
Alice16
Anna16
Bob16
Joe16
Sam16

Stream Mode

Returns the same columns as run mode, streamed for memory efficiency.

GQL
CALL algo.wcc.stream() YIELD nodeId, componentId, componentSize
RETURN componentId, COLLECT(nodeId) AS members, componentSize
GROUP BY componentId

Result:

componentIdmemberscomponentSize
0["Mike", "Cathy"]2
1["Bill", "Alice", "Anna", "Bob", "Joe", "Sam"]6

Stats Mode

Returns:

ColumnTypeDescription
nodeCountINTTotal number of nodes
componentCountINTNumber of connected components
largestComponentSizeINTSize of the largest component
smallestComponentSizeINTSize of the smallest component
GQL
CALL algo.wcc.stats() YIELD nodeCount, componentCount, largestComponentSize, smallestComponentSize

Result:

nodeCountcomponentCountlargestComponentSizesmallestComponentSize
8262

Write Mode

Computes results and writes them back to node properties. The write configuration is passed as a second argument map.

Write parameters:

NameTypeDescription
db.propertySTRING or MAPNode property to write results to. String: writes the componentId column in results to a property. Map: explicit column-to-property mapping (e.g., {componentId: 'wcc_id'}).

Writable columns:

ColumnTypeDescription
componentIdINTComponent identifier
componentSizeINTComponent size

Returns:

ColumnTypeDescription
task_idSTRINGTask identifier for tracking via SHOW TASKS
nodesWrittenINTNumber of nodes with properties written
computeTimeMsINTTime spent computing the algorithm (milliseconds)
writeTimeMsINTTime spent writing properties to storage (milliseconds)
GQL
CALL algo.wcc.write({}, {
  db: {
    property: "wcc_id"
  }
}) YIELD task_id, nodesWritten, computeTimeMs, writeTimeMs