强连通分量算法(3)
2011-02-28 14:24
239 查看
Cheriyan–Mehlhorn/Gabow algorithm
这个算法的思路和tarjan算法差不多,效率要比tarjan算法快一点。算法需要两个栈来进行维护。
下面这个伪代码是tarjan的伪代码修改过来的。从结构上看非常的相似。
algorithm gabow is input: graph G = (V, E) output: set of strongly connected components (sets of vertices) index := 1 S1 := empty S2 := empty for each v in V do if (v.index is undefined) strongconnect(v) end if repeat function strongconnect(v) // Set the depth index for v to the smallest unused index v.index := index index := index + 1 S1.push(v) S2.push(v) // Consider successors of v for each (v, w) in E do if (w.index is undefined) then // Successor w has not yet been visited; recurse on it strongconnect(w) else if (w is in S1) then // Successor w is in stack S1 and hence in the current SCC While( S2.top.index>w.index ) S2.top--; end if repeat // If v is a root node, pop the stack and generate an SCC if (i==S2.top) then start a new strongly connected component S2.top--; repeat w := S1.pop() add w to current strongly connected component until (w = v) output the current strongly connected component end if end function
对于这样一个图:我们手动执行一遍程序
1.
第一步
DFN
= [1]
S1
= [1]
S2
= [1]
2.
第二步
DFN=[1
2]
S1
= [1 3]
S2
=[1 3]
3.
第三步
DFN=[1
2 3]
S1
=[1 3 5]
S2
=[1 3 5]
4.
第四步
DFN=[1
2 3 4]
S1
= [1 3 5 6]
S2
= [1 3 5 6]
5.
第五步
I
= 6
I
= top of S2;
DFN=[1
2 3]
S1=[1
3 5]
S2=[1
3 5]
6.
第六步
I=5
I=top
of S2
DFN=[1
2]
S1=[1
3]
S2=[1
3]
7.
第七步
I=3,继续搜
DFN
= [1 2 5]
S1=[1
3 4]
S2=[1
3 4]
8.
第八步
I=4,继续搜
碰到1,已经存在于S1,那么要处理S2
DFN=[1
2 5]
S1=[1
3 4]
S2=[1]
9.
第九步
回到I=3
10.
第十步
回到I=1,继续搜
DFN=[1
2 5 6]
S1=[1
3 4 2]
S2=[1
2]
11.
第十一步
I=4,已经存在于S1中,处理S2
DFN=[1
2 5 6]
S1=[1
3 4 2]
S2=[1]
12.
第十二步
回到I=2
回到I=1
I==top
of S2
从S1中弹出一个scc
S1
= []
S2
= []
算法执行完毕
相关文章推荐
- 强连通分量及缩点tarjan算法解析
- 强连通分量两种算法。tarjan和kosaraju
- Kosaraju算法、Tarjan算法分析及证明--强连通分量的线性算法
- 第22章:基本的图算法—拓扑排序和有向图强连通分量
- 有向图强连通分量的三种算法
- Targan 算法[有向图强连通分量]
- 强连通分量分解--Kosaraju算法分析与证明
- 图论算法(6) --- Tarjan算法求强连通分量
- Targan 算法[有向图强连通分量]
- tarjan算法之 强连通分量
- 强连通分量算法; 重在理解原理分析 ; 算法导论讲的很明白;
- soj 3134: windy和水星 Stoer-Wagner算法求无向图的最小割集:一个无向连通网络,去掉一个边集可以使其变成两个连通分量则这个边集就是割集;最小割集当然就权和最小的割集
- 【转】有向图强连通分量的Tarjan算法
- 【数据结构】算法7.7-7.8 无向图的连通分量和生成树
- tarjan 算法模板(边连通分量)
- 算法-无向图(连通分量,是否有环和二分图)
- 算法笔记_144:有向图强连通分量的Tarjan算法(Java)
- 强连通分量 Tarjan 算法入门笔记
- Tarjan求解有向图强连通分量的线性时间的算法
- 求强连通分量的三种算法——Kosaraju, Tarjan, Gabow