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

Strongly Connected Components (SCC)

Overview

The SCC algorithm identifies the strongly connected components in a directed graph using Kosaraju's algorithm. A strongly connected component is a maximal subset of nodes where there is a directed path between every pair of nodes in both directions.

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.

Strongly Connected Component

A strongly connected component (SCC) is a maximal subset of nodes in a directed graph where for any two nodes u and v, there exists a directed path from u to v and from v to u. All edges along these paths follow the original direction.

Unlike WCC which ignores edge direction, SCC respects it — two nodes are in the same SCC only if they can reach each other following directed edges.

This example shows 3 strongly connected components and 2 weakly connected components. The number of SCCs is always ≥ the number of WCCs, since SCCs impose stricter connectivity conditions.

Considerations

  • The algorithm respects edge direction.
  • Each isolated node constitutes its own strongly 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.scc() YIELD nodeId, componentId, componentSize

Result:

nodeIdcomponentIdcomponentSize
Mike01
Bill25
Alice25
Anna25
Bob25
Joe25
Cathy31
Sam11

Stream Mode

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

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

Result:

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

Stats Mode

Returns:

ColumnTypeDescription
nodeCountINTTotal number of nodes
communityCountINTNumber of strongly connected components
largestCommunitySizeINTSize of the largest component
smallestCommunitySizeINTSize of the smallest component
GQL
CALL algo.scc.stats() YIELD nodeCount, communityCount, largestCommunitySize, smallestCommunitySize

Result:

nodeCountcommunityCountlargestCommunitySizesmallestCommunitySize
8451

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: 'scc_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.scc.write({}, {
  db: {
    property: "scc_id"
  }
}) YIELD task_id, nodesWritten, computeTimeMs, writeTimeMs