Bu içerik Türkçe olarak yazılmış olup yapay zeka ile otomatik olarak İngilizceye çevrilmiştir.
Tarjan's algorithm is a graph algorithm designed to detect strongly connected components (SCCs) in directed graphs. The purpose of the algorithm is to partition a graph into subcomponents, identifying nodes within each component that have mutual reachability. A strongly connected component is a subgraph in which there exists a directed path between any two nodes.
Tarjan's algorithm is based on the depth-first search (DFS) approach. Each node is assigned a unique index as it is discovered, and a lowlink value is computed for each index. The lowlink value represents the smallest index reachable from the node through its subtree in the DFS tree. During discovery, the algorithm temporarily stores nodes on a stack and identifies a strongly connected component when it is fully explored by popping the relevant nodes from the stack.
Tarjan's algorithm employs the following data structures:
The time complexity of Tarjan's algorithm is O(V + E), where V is the number of vertices and E is the number of edges. This complexity arises because the algorithm processes each vertex and edge exactly once. The space complexity is O(V), due to the additional data structures used.
Tarjan's algorithm is used in various fields of computer science. Notable applications include social network analysis, compiler optimization, web crawling, biological network analysis, circuit design, dependency resolution, and network reliability analysis.
Consider the following directed graph:
This graph contains two strongly connected components (SCCs):
1. DFS Start: Begin at node 0.
2. Index and Lowlink Values: Each node is assigned an index in the order of discovery. The initial lowlink value of a node is set to its own index.
3. Stack Usage: Visited nodes are pushed onto the stack.
4. Back Edges: If a visited node can reach another node already on the stack, its lowlink value is updated to the minimum of its current value and the index of the reachable node.
5. Component Detection: If a node’s lowlink value equals its index, it is the root of a strongly connected component. Nodes are popped from the stack until this root is reached, forming one SCC.
【1】
Tarjan's algorithm was developed in 1972 by American computer scientist Robert Tarjan. The algorithm was introduced in Tarjan’s paper titled "Depth-first search and linear graph algorithms." Tarjan also contributed to the development of other data structures, including splay trees and Fibonacci heaps.
An alternative to Tarjan's algorithm for finding strongly connected components is Kosaraju's algorithm. Kosaraju’s algorithm requires two separate DFS traversals and the reversal of the graph, whereas Tarjan’s algorithm achieves the result with a single DFS traversal. Additionally, variants optimized for parallel processing have been proposed in the literature.
[1]
Bileşen içindeki düğümlerin sırası yığından çıkarılma sırasına göre olabilir.
Basic Working Principle
Data Structures Used
Time and Space Complexity
Applications
Step-by-Step Execution of Tarjan's Algorithm on an Example
Used Graph
The edge list of the graph is as follows:
Step-by-Step Execution of the Algorithm
Implementation of Tarjan's Algorithm in Python
Output
Step-by-Step Explanation
History
Similar Algorithms and Variants