Professional Documents
Culture Documents
Computing Strongly
Connected Components
Daniel Kane
Department of Computer Science and Engineering
University of California, San Diego
Graph Algorithms
Data Structures and Algorithms
Learning Objectives
Eciently compute the strongly
connected components of a directed
graph.
Last Time
1 Sink Components
2 Algorithm
Sink Components
Idea: If v is in a sink SCC, explore(v ) nds
vertices reachable from v . This is exactly the
SCC of v .
Finding Sink Components
Theorem
If C and C 0 are two strongly connected
components with an edge from some vertex
of C to some vertex of C 0, then largest post
in C bigger than largest post in C 0.
Proof
Cases:
Visit C before visit C 0
Visit C 0 before visit C
Case I
Visit C rst.
Can reach everything in C 0 from C .
Explore all of C 0 while exploring C .
C has largest post.
Case II
Visit C 0 rst.
Cannot reach C from C 0
Must nish exploring C 0 before exploring
C
C has largest post.
Conclusion
1 Sink Components
2 Algorithm
Basic Algorithm
SCCs(G )
run DFS(G R )
let v have largest post number
run Explore(v )
vertices found are first SCC
Remove from G and repeat
Example
Example
Example
Example
Example
Example
Example
Example
Example
Example
Example
Improvement