Skip to content

Conversation

coddingjatin
Copy link
Contributor

Tarjan’s Algorithm in Java

This Java program implements Tarjan’s Algorithm to find Strongly Connected Components (SCCs) in a directed graph using an efficient Depth First Search (DFS) approach.

Each node is assigned a discovery time and a low-link value that helps track the earliest reachable vertex.
By maintaining a stack of active nodes, the algorithm identifies when a node is the root of an SCC and extracts all nodes belonging to that component.

It’s widely used in graph theory, compiler design, and network analysis to detect cycles or modular dependencies within complex systems.

Key Features:

  • Uses DFS and low-link concepts to identify SCCs.

  • Handles multiple disconnected components.

  • Prints each SCC as a separate group of vertices.

Complexity Analysis:

Time Complexity: O(V + E) - each vertex and edge is processed once.

Space Complexity: O(V) - for recursion stack, auxiliary arrays, and the vertex stack

Copy link
Owner

@IamBisrutPyne IamBisrutPyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @coddingjatin

This is an outstanding contribution.
The Tarjan's Algorithm is a perfect addition to the Algorithms folder.

Happy Hacking ✨

@IamBisrutPyne IamBisrutPyne merged commit 9889f99 into IamBisrutPyne:main Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants