What Is Strongly Connected Components in Data Structure?


Scott Campbell

What Is Strongly Connected Components in Data Structure?

A strongly connected component (SCC) is a subgraph in a directed graph where there is a path between every pair of vertices. In other words, each vertex in the SCC can be reached from every other vertex in the same SCC. SCCs are an important concept in data structures and have numerous applications, including graph algorithms, network analysis, and data compression.

How to Find Strongly Connected Components?

To find the strongly connected components in a directed graph, we can use Tarjan’s algorithm. This algorithm is based on depth-first search (DFS) and uses a special data structure called a stack to keep track of visited vertices and their low-link values.

Tarjan’s Algorithm:

  1. Create an empty stack and initialize visited and low-link values for all vertices as -1.
  2. For each vertex v in the graph:
    • If v has not been visited, call the DFS function with v as the starting point.
  3. In the DFS function:
    • Mark the current node as visited and push it onto the stack.
    • Set both the visited and low-link values of the current node to the current index value.
    • Increment the index value by one.
    • For each adjacent vertex u of the current node:
      • If u has not been visited, recursively call the DFS function with u as the starting point.
      • If u is on the stack, update the low-link value of the current node with the minimum of its current low-link value and the low-link value of u.
    • If the low-link value of the current node is equal to its visited value (indicating that it is the root of an SCC):
      • Create a new SCC.
      • Pop vertices from the stack until the current node is popped out.
      • Add all popped vertices to the SCC.


Let’s take an example to understand how Tarjan’s algorithm works. Consider the following directed graph:

A -> B -> C -> D
|    |    |    ^
v    v    v    |
E <- F <- G <- H

After applying Tarjan's algorithm, we find that there are two strongly connected components in this graph:

  1. {A, B, F, E}
  2. {C, D, G, H}


Strongly connected components play a vital role in analyzing and understanding complex directed graphs. Tarjan's algorithm provides an efficient way to find these components and can be applied to various real-world scenarios such as identifying interconnected communities in social networks or finding cycles in computer networks.

In this tutorial, we explored what strongly connected components are and how to find them using Tarjan's algorithm. By understanding this fundamental concept in data structures, you can enhance your ability to solve graph-related problems efficiently.

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy