In the mathematical theory of directed graphs, a graph is said to be strongly connected or diconnected if every vertex is reachable from every other vertex.
有向图强连通分量的Tarjan算法
(“郭家寶”,个人网站byvoid.com 的页面
强烈推荐大神的博客)
直接根据定义,用双向遍历取交集的方法求强连通分量,时间复杂度为O(N^2+M)。更好的方法是Kosaraju算法或Tarjan算法,两者的时间复杂度都是O(N+M)。本文介绍的是Tarjan算法。
Graph Traversal Algorithms
This visualization is rich with a lot of DFS and BFS variants (all run in O(V+E)) such as:
* Topological Sort algorithm (both DFS and BFS/Kahn's algorithm version),
* Bipartite Graph Checker algorithm (both DFS and BFS version),
* Cut Vertex & Bridge finding algorithm,
* Strongly Connected Components (SCC) finding algorithms
(both Kosaraju's and Tarjan's version), and
2-SAT Checker algorithm.
Tarjan algorithm
undefined?
function strongconnect()
v.index
v.lowlink
Kosaraju algorithm
- G_rev
- DFS求G_rev的逆后排序
- 对逆后排序再次进行DFS
- 同一个SCC:同一个DFS recursion访问的所有顶点。
Strongly Connected Components Kosaraju's Algorithm Graph Algorithm
网友评论