This guide explains Strongly Connected Components (SCC) from first principles. The goal is to understand the problem it solves, why the algorithm works, how to implement it, and where it appears in real software systems.
What problem does it solve?
Strongly Connected Components (SCC) belongs to the graph-algorithm toolbox. Before coding, define what the vertices represent, what an edge means, and what result the system actually needs.
The core idea in simple terms
در گراف جهتدار mutual reachability مهم است. Kosaraju و Tarjan دو راه معروف خطی هستند.
Step-by-step process
- در Kosaraju DFS اول ترتیب پایان را میسازد.
- یالها Reverse میشوند.
- رأسها با ترتیب معکوس پایان پردازش میشوند.
- هر DFS جدید یک SCC میسازد.
JavaScript example
// Kosaraju: DFS finishing order -> reverse edges -> DFS in reverse order.
// Each DFS tree in the reversed graph is one SCC.
function reverseGraph(graph) {
const r = {};
for (const u of Object.keys(graph)) {
r[u] ??= [];
for (const v of graph[u]) { r[v] ??= []; r[v].push(u); }
}
return r;
}Real-world and workplace examples
- Circular Dependencies
- ماژولهای شدیداً وابسته
- گروه ارتباطی دوطرفه
- Condensation Graph
Time and space complexity
O(V + E) time
When should you use it?
Use it when the problem matches this condition: تحلیل ارتباط رفتوبرگشتی در گراف جهتدار.
When is it not a good fit?
It is usually not the best choice when: در گراف بدونجهت Connected Components کافی است..
Summary
Do not choose an algorithm by name alone. First identify whether the graph is directed or undirected, weighted or unweighted, and whether the goal is traversal, reachability, shortest path, connectivity, spanning structure, or combinatorial optimization.