Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
IntroductionStrong Components
Biconnected Components
Path-based depth-first search for strong andbiconnected components
Author of the paper: Harold N. Gabow
Reported by: T.T. Liu D.P. Xu B.Y. Chen
June 6, 2017
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
Outline
1 Introduction
2 Strong ComponentsReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
3 Biconnected ComponentsReviewHigh-Level AlgorithmGabow’s Algorithms
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
Characterastics of Gabow’s Algorithms
One-pass algorithm. But for the algorithm of strongcomponents, what we have learned from the textbook is atwo-pass algorithm, by which we must traverse the wholegraph twice.Lower time and space complexity. This algorithm only usetwo stacks and an array, and do not employ a disjoint-setdata structure.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Outline
1 Introduction
2 Strong ComponentsReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
3 Biconnected ComponentsReviewHigh-Level AlgorithmGabow’s Algorithms
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Review: What have we learned from the textbook?Concepts of Strong Components
Two mutually reachable vertices are in the same strongcomponent.It is a equivalence relation.
2
5
1
4
6
3
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Review: What have we learned from the textbook?Algorithms to Find Strong Components
Idea: Run DFS twice: Once on the original graph G, onceon its transpose GT .Trick: Using finishing times of each vertex computed by thefirst DFS.Linear time complexity: O(V + E)
Proposed by S. Rao Kosaraju, known as the Kosaraju’sAlgorithm.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Outline
1 Introduction
2 Strong ComponentsReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
3 Biconnected ComponentsReviewHigh-Level AlgorithmGabow’s Algorithms
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Purdom and Munro’s High-Level Algorithm: Plain text
Initially H is the given graph G. If H has no vertices stop.Otherwise start a new path P by choosing a vertex v andsetting P = (v). Continue by growing P as follows.To grow the path P = (v1, · · · , vk) choose an edge (vk,w)directed from the last vertex of P and do the following:
If w /∈ P, add w to P, making it the new last vertex of P.Continue growing P.If w ∈ P, say w = vi, contract the cycle vi, vi+1, · · · , vk, bothin H and in P. P is now a path in the new graph H. Continuegrowing P.If no edge leaves vk, output vk as a vertex of the strongcomponent graph. Delete vk from both H and P. If P is nownonempty continue growing P. Otherwise try to start a newpath P.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { }Initially, H = G.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1} }Grow P by adding v1.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1}, {2} }Grow P by adding v2.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1}, {2}, {3} }Grow P by adding v3.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1}, {2} } {3}As v3 is isolated, no edge leaves from v3, so just delete it.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1}, {2}, {4} } {3}Grow P by adding v4.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1}, {2}, {4}, {5} } {3}Grow P by adding v5.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1}, {2, 4, 5} } {3}The cycle v2, v4, v5 in P is detected. Contract this cycle.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1}, {2, 4, 5}, {6} } {3}Grow P by adding v6.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1}, {2, 4, 5, 6} } {3}The cycle {v2, v4, v5}, v6, v4 in P is detected. Contract thiscycle.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { {1} } {2, 4, 5, 6}, {3}No edge leaves from {v2, v4, v5, v6}, so we delete it.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { } {1}, {2, 4, 5, 6}, {3}No edge leaves from {v1}, so we delete it.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: P&M’s High-Level Algorithm
2
5
1
4
6
3
Path P = { } {1}, {2, 4, 5, 6}, {3}Now graph H is empty, which has no vertex.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Correctness
Correctness: If no edge leaves vk then vk is a vertex of thefinest acyclic contraction.Easy to prove by contradiction: If no edge leaves vk, but vk
is not a vertex of the finest acyclic contraction. That is tosay, vk is a part of some strong component S′, so there is avertex v′ ∈ S′, which satisfies vk 6= v′ while vk and v′ aremutually reachable. Therefore, one edge at least leaving vk
must be existent.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Three Cases When Growing Path
To grow the path P = (v1, · · · , vk) choose an edge (vk,w)directed from the last vertex of P and do the following:
1 If w /∈ P, add w to P, making it the new last vertex of P.Continue growing P.
2 If w ∈ P, say w = vi, contract the cycle vi, vi+1, · · · , vk, bothin H and in P. P is now a path in the new graph H. Continuegrowing P.
3 If no edge leaves vk, output vk as a vertex of the strongcomponent graph. Delete vk from both H and P. If P is nownonempty continue growing P. Otherwise try to start a newpath P.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
How to implement by DFS?
SCCvr vs
vt
vu
Assume the current node is vs which has two adjacentnodes. The current path is P = (· · · , vr, · · · , vs).For the node vu incident from vs but also in the SCC, afterrunning Sub-DFS() on this node, vu will be removed withthe SCC.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Pseudo Code
Algorithm 1: Strong components: Main-DFS(G) (DFS caller)H = G;while H still has a vertex v do
Sub-DFS(v); /* start a new path P = (v) */
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Pseudo Code
Algorithm 2: Strong components: Sub-DFS(v) (DFS callee)add the v as the new last vertex of path P;for w ∈ {vertices adjacent to v} do
if w /∈ P thenSub-DFS(w);
else /* w = vi, and v = vk */contract the cycle vi, vi+1, · · · , vk, both in H and in P;
if no edge leaves v thenoutput v as a vertex of the strong component graph;delete v from both H and P;
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Assessment
The time consumption of each statement in thepseudo-code is clear. Total time complexity is linear.except this statement:
contract the cycle vi, vi+1, · · · , vk, both in H and in P;
Problem is how to merge in linear time while keeping thenext time accessing this vertex still in constant time.Therefore, a good data structure for disjoint-set merging isneeded usually.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Outline
1 Introduction
2 Strong ComponentsReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
3 Biconnected ComponentsReviewHigh-Level AlgorithmGabow’s Algorithms
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Gabow’s Contribution
He gave a simple list-based implementation that achieveslinear time.Use only stacks and arrays as data structure.Do not need a disjoint set merging data structure.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Data Structure Used in Algorithm
In DFS, the path P from root to each node is almost alwayssignificant. So it is in this algorithm.A stack S contains the sequence of vertices in P.A stack B contains the boundaries between contractedvertices.An array I[1 . . . n] is used to store stack S indicescorresponding to vertices.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Contraction Makes Much Difference
S and B correspond to P = (v1, · · · , vk) where k = TOP(B)and for i = 1, · · · , k.When contraction is executed, some vertices merges into aset.It is possible that several elements in stack S are in thesame vertex in path P. More formal,
vi = {S[j]|B[i] ≤ j < B[i + 1]}
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Contraction Makes Much Difference
By the way, the formal definition of I[v] is
I[v] =
0, if v has never been in P;j, if v is currently in P and S[j] = v;c, if the strong component containing v has
been deleted and numbered as c.
where c counts from n + 1.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
New Algorithm to Discover Strong Components
Procedure 3: STRONG(G)empty stacks S and B;for v ∈ V do
I[v] = 0;c = n;for v ∈ V do
if I[v] = 0 then /* vertex v has never beenaccessed yet */
DFS(v);
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
New Algorithm to Discover Strong Components
Procedure 4: DFS(v)PUSH(v, S); I[v] =TOP(S); PUSH(I[v],B);/* add v to the end of P */for egdes(v,w) ∈ E do
if I[w] = 0 thenDFS(w);
else /* contract if necessary */while I[w] < B[TOP(B)] do
POP(B);if I[v] = B[TOP(B)] then /* number vertices of the nextstrong component */
POP(B);c = c + 1;while I[v] ≤TOP(S) do
I[POP(S)] = c;
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
000000
Graph H
2
5
1
4
6
3
Call stack: STRONG()This state is the first after initialized. DFS(1) is going to becalled.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
1 → 1 100000
Graph H
2
5
1
4
6
3
Call stack: STRONG()→DFS(1)Code: for edges(v,w)∈E do · · ·w = 2.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
12→→
12
120000
Graph H
2
5
1
4
6
3
Call stack: STRONG()→DFS(1)→DFS(2)Code: for edges(v,w)∈E do · · ·w = 3.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
123
→→→
123
123000
Graph H
2
5
1
4
6
3
Call stack: STRONG()→DFS(1)→DFS(2)→DFS(3)Code: if I[v]=B[TOP(B)] then · · ·Go back.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
123
→→→
124
127300
Graph H
2
5
1
4
6
3
Call stack: STRONG()→DFS(1)→DFS(2)→DFS(4)Code: for edges(v,w)∈E do · · ·w = 5.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
1234
→→→→
1245
127340
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(1)→DFS(2)→DFS(4)→DFS(5)Code: for edges(v,w)∈E do · · ·w = 2.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
1234
→→→→
1245
127340
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(1)→DFS(2)→DFS(4)→DFS(5)Code: while I[w]<B[TOP(B)] do POP(B);
Now, w = 2, contract!Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
12→→
1245
127340
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(1)→DFS(2)→DFS(4)→DFS(5)Code: while I[w]<B[TOP(B)] do POP(B);
Now, w = 2, contract!Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
12→→
1245
127340
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(1)→DFS(2)→DFS(4)→DFS(5)Code: if I[w]= 0 then DFS(w);
w = 6.Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
125
→→
→
12456
127345
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(2)→DFS(4)→DFS(5)→DFS(6)Code: for edges(v,w)∈E do ...
w = 4.Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
125
→→
→
12456
127345
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(2)→DFS(4)→DFS(5)→DFS(6)Code: while I[w]<B[TOP(B)] do POP(B);
Now, w = 4, contract!Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
12→→
12456
127345
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(2)→DFS(4)→DFS(5)→DFS(6)Code: if I[v]=B[TOP(B)] then ...
Go back.Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
12→→
12456
127345
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(2)→DFS(4)→DFS(5)Code: if I[v]=B[TOP(B)] then ...
Go back.Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
12→→
12456
127345
Graph H
2
5
1
4
6
3
Call stack: · · · →DFS(2)→DFS(4)Code: if I[v]=B[TOP(B)] then ...
Go back.Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
12→→
12456
127345
Graph H
2
5
1
4
6
3
Call stack: STRONG()→DFS(1)→DFS(2)Code: if I[v]=B[TOP(B)] then ...
Go back. But this time, Condition in last line is satisfied!Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
1 → 1 187888
Graph H
2
5
1
4
6
3
Call stack: STRONG()→DFS(1)→DFS(2)Code: while I[v]≤TOP(S) do I[POP(S)]=c;
Pop 2 from B, while 2, 4, 5, 6 in S are also popped.Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Demo: Gabow’s Strong Components Algorithm
Data in memoryB and S: stack. I: array.
B S I123456
987888
Graph H
2
5
1
4
6
3
Call stack: STRONG()→DFS(1)Code: while I[v]≤TOP(S) do I[POP(S)]=c;
Pop the last one both in B and in S. Finished!!Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Outline
1 Introduction
2 Strong ComponentsReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
3 Biconnected ComponentsReviewHigh-Level AlgorithmGabow’s Algorithms
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Correctness of Gabow’s Strong ComponentsAlgorithm
Theorem (Correctness and complexity)When STRONG(G) halts each vertex v ∈ V belongs to thestrong component numbered I[v]. The time and space are bothO(V + E).
The key of proof is to show that STRONG(G) is a validimplementation of the P&M’s high-level algorithm.Tip: Use induction as a tool.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Framework of STRONG(G)
Algorithm 5: Strong components: Main-DFS(G) (DFS caller)H = G;while H still has a vertex v do
Sub-DFS(v); /* start a new path P = (v) */
Procedure 6: STRONG(G)empty stacks S and B;for v ∈ V do
I[v] = 0;c = n;for v ∈ V do
if I[v] = 0 then /* v has never been accessed */DFS(v);
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Growing Path P
Algorithm 7: A Part of High-Level Algorithmfor w ∈ {vertices adjacent to v} do
if w /∈ P thenSub-DFS(w);
else /* w = vi, and v = vk */contract the cycle vi, vi+1, · · · , vk, both in H and in P;
Procedure 8: A Part of DFS(v)for egdes(v,w) ∈ E do
if I[w] = 0 thenDFS(w);
else /* contract if necessary */while I[w] < B[TOP(B)] do
POP(B);
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Having Found a Strong Components
Algorithm 9: A Part of High-Level Algorithmif no edge leaves v then
output v as a vertex of the strong component graph;delete v from both H and P;
Procedure 10: A Part of DFS(v)if I[v] = B[TOP(B)] then /* number vertices of the nextstrong component */
POP(B);c = c + 1;while I[v] ≤TOP(S) do
I[POP(S)] = c;
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
Time Complexity
Every vertex is pushed onto and popped from each stackS, B exactly once. So the algorithm spends O(1) time oneach vertex or edge.Time complexity: O(V + E)
Intuitively, from another view, this algorithm is based onDFS, and no loop is executed on one vertex or one edge.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Outline
1 Introduction
2 Strong ComponentsReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
3 Biconnected ComponentsReviewHigh-Level AlgorithmGabow’s Algorithms
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Review: Biconnected Component
A biconnected component of G is a maximal set of edgessuch that any two edges in the set lie on a common simplecycle.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Outline
1 Introduction
2 Strong ComponentsReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
3 Biconnected ComponentsReviewHigh-Level AlgorithmGabow’s Algorithms
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Concepts: Hypergraph
A hypergraph H = (V,E) is a generalization of a graph inwhich an edge can join any number of vertices.In the following hypergraph,
V = {v1, v2, v3, v4, v5, v6, v7}E = {e1, e2, e3, e4}= {{v1, v2, v3}, {v2, v3}, {v3, v5, v6}, {v4}}
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Concepts: Hypergraph
Therefore, we need redefine the edge, path, cycle, · · · , andnearly all concepts as long as it is relative to edge.A path is a sequence (v1, e1, · · · , ei−1, vi, ei, vi+1, · · · , vk, ek)of distinct vertices vi and distinct edges ei, 1 ≤ i ≤ k, withv1 ∈ e1 and vi ∈ ei−1 ∩ ei for every 1 < i ≤ k.An important property:
vi+1 ∈ ei − {vi}, or vi ∈ ei − {vi+1}, 1 ≤ i < k
To merge a set of edges is to replace old edges with thenew one:
enew =
k⋃i=1
ei
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Addtional Concepts We Need
The block hypergraph H of G is the hypergraph formed bymerging the edges of each biconnected component of G.The set of all vertices in edges of P is denoted
V(P) =k⋃
i=1
ei
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
High-Level Algorithm in Plain Text
Initially H is the given graph G. If H has no edges stop.Otherwise start a new path P by choosing an edge {v, w}and setting P = (v, {v, w}). Continue by growing P.To grow the path P = (v1, e1, · · · , vk, ek) choose an edge{v, w} 6= ek with v ∈ ek − {vk} and do:
If w /∈ V(P), add v, {v, w} to the end of P. Continue growingP.If w ∈ V(P), say w ∈ ei − {vi+1}, merge the edges of thecycle w, ei, vi+1, ei+1, · · · , vk, ek, v, {v, w} to a new edgee =
⋃kj=i ej, both in H and in P. Continue growing P.
If no edge leaves ek − {vk}, output ek as an edge of theblock hypergraph. Delete ek from H and delete (vk, ek) fromP. If P is now nonempty continue growing P. Otherwise tryto start a new path P.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Pseudo Code
Algorithm 11: Biconnected Components: Main-DFS (DFScaller)H = G;while H still has an edge {v, w} do
Sub-DFS(v); /* start a new path P = (v, {v, w}) */
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Pseudo Code
Algorithm 12: Biconnected Components: Sub-DFS (DFScallee)add the v as the new last vertex of path P;for w ∈ {vertices adjacent to v} do /* Grows path P */
if w /∈ V{P} thenadd {v, w} to the end of P, as the new last edge of P;Sub-DFS(w);remove the edge {v, w} if necessary;
else /* w ∈ ei − {vi+1}, but most likely w 6= vi */replace the cycle w, ei, vi+1, ei+1, · · · , vk, ek, v to a new edge
e =⋃k
j=i ej, both in H and in P;if no edge leaves ek − {vk} then
output ek as an edge of the block hypergraph;delete ek from H and delete (vk, ek) from P;
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Correctness: Validity of Path and Cycle
Pseudo code: "To grow the path P = (v1, e1, · · · , vk, ek)choose an edge {v, w} 6= ek with v ∈ ek − {vk} and do:"Distinct vertices: When v, {v, w} is added to P the result isa valid path, by the condition v ∈ ek − {vk}.Distinct edges: When edges are merged they form a validcycle, by the condition {v, w} 6= ek.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Correctness: Finest Acyclic Merging
Pseudo code:If w /∈ V(P), add v, {v, w} to the end of P. Continue growingP.If w ∈ V(P), say w ∈ ei − {vi+1}, merge the edges of thecycle w, ei, vi+1, ei+1, · · · , vk, ek, v, {v, w} to a new edgee =
⋃kj=i ej, both in H and in P. Continue growing P.
If no edge leaves ek − {vk}, output ek as an edge of theblock hypergraph. Delete ek from H and delete (vk, ek) fromP. If P is now nonempty continue growing P. Otherwise tryto start a new path P.
Finest: The algorithm correctly forms the finest acyclicmerging of G, which finds the block hypergraph as desired.The proof employs the contradiction very similar to that instrong components.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Outline
1 Introduction
2 Strong ComponentsReviewsPurdom and Munro’s High-Level AlgorithmContributionDiscussion
3 Biconnected ComponentsReviewHigh-Level AlgorithmGabow’s Algorithms
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Data Structure Used in Algorithm
A stack S contains the vertices V(P).A stack B contains the boundaries between edges of P,two vertices per boundary.An array I[1 . . . n] is used to store stack indicescorresponding to vertices.All of above are similar (but not the same) to these instrong components.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Algorithms
Procedure 13: BICONN(G)empty stacks S and B;for v ∈ V do
I[v] = 0;c = n;for v ∈ V do
if I[v] = 0 and v is not isolated thenDFS(v);
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Algorithms
Procedure 14: DFS(v)PUSH(v, S); I[v] =TOP(S);if I[v] > 1 then /* create a filled arrow on B */
PUSH(I[v],B);for egdes{v,w} ∈ E do
if I[w] = 0 then /* create an open arrow on B */PUSH(I[v],B); DFS(w);
else /* possible merge */while I[v] > 1 and I[w] < B[TOP(B)− 1] do
POP(B); POP(B);if I[v] = 1 then
I[POP(S)] = c;else if I[v] = B[TOP(B)] then
POP(B); POP(B); c = c + 1;while I[v] ≤TOP(S) do I[POP(S)] = c;
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Representations
Open arrows: They point to the vertices vi of P.
vi = S[B[2i− 1]], i = 1, · · · , k
Filled arrows: They demarcate the sets ei − {vi}; thesesets are the "nonfirst" vertices of edges ei of P.
ei − {vi} = {S[j]|B[2i] ≤ j < B[2i + 2]}, i = 1, · · · , k
Biconnected components: Each edge {v, w} belongs tothe biconnected component with number min{I[v], I[w]}.
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
0000000
Graph
1
2
3
4
5
6
7
Procedure: BICONN(G)P = { }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
1 1 1000000
Graph
1
2
3
4
5
6
7
Procedure: DFS(1): w=2P = { v1, {v1, v2} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12
12
1200000
Graph
1
2
3
4
5
6
7
Procedure: DFS(2)P = { v1, {v1, v2} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
122
12
1200000
Graph
1
2
3
4
5
6
7
Procedure: DFS(2): w=3P = { v1, {v1, v2}, v2, {v2, v3} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
1223
123
1230000
Graph
1
2
3
4
5
6
7
Procedure: DFS(3)P = { v1, {v1, v2}, v2, {v2, v3} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12
123
1230000
Graph
1
2
3
4
5
6
7
Procedure: DFS(3): w=1P = { v1, {v1, v2, v3} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
123
123
1230000
Graph
1
2
3
4
5
6
7
Procedure: DFS(3): w=4P = { v1, {v1, v2, v3}, v3, {v3, v4} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
1234
1234
1234000
Graph
1
2
3
4
5
6
7
Procedure: DFS(4)P = { v1, {v1, v2, v3}, v3, {v3, v4} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12
1234
1234000
Graph
1
2
3
4
5
6
7
Procedure: DFS(4): w=2P = { v1, {v1, v2, v3, v4} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
124
1234
1234000
Graph
1
2
3
4
5
6
7
Procedure: DFS(4): w=5P = { v1, {v1, v2, v3, v4}, v4, {v4, v5} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
1245
12345
1234500
Graph
1
2
3
4
5
6
7
Procedure: DFS(5)P = { v1, {v1, v2, v3, v4}, v4, {v4, v5} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12
12345
1234500
Graph
1
2
3
4
5
6
7
Procedure: DFS(5): w=3P = { v1, {v1, v2, v3, v4, v5} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
125
12345
1234500
Graph
1
2
3
4
5
6
7
Procedure: DFS(5): w=6P = { v1, {v1, v2, v3, v4, v5}, v5, {v5, v6} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
1256
123456
1234560
Graph
1
2
3
4
5
6
7
Procedure: DFS(6)P = { v1, {v1, v2, v3, v4, v5}, v5, {v5, v6} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12566
123456
1234560
Graph
1
2
3
4
5
6
7
Procedure: DFS(6): w=7P = { v1, {v1, v2, v3, v4, v5}, v5, {v5, v6}, v6, {v6, v7} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
125667
1234567
1234567
Graph
1
2
3
4
5
6
7
Procedure: DFS(7)P = { v1, {v1, v2, v3, v4, v5}, v5, {v5, v6}, v6, {v6, v7} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
1256
1234567
1234567
Graph
1
2
3
4
5
6
7
Procedure: DFS(7): w=5P = { v1, {v1, v2, v3, v4, v5}, v5, {v5, v6, v7} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
1256
1234567
1234567
Graph
1
2
3
4
5
6
7
Procedure: DFS(7): EndP = { v1, {v1, v2, v3, v4, v5}, v5, {v5, v6, v7} }
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12
12345
1234588
Graph
1
2
3
4
5
6
7
Procedure: DFS(6): EndP = { v1, {v1, v2, v3, v4, v5} } {v5, v6, v7}
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12
12345
1234588
Graph
1
2
3
4
5
6
7
Procedure: DFS(5): End(No operation when w=7)P = { v1, {v1, v2, v3, v4, v5} } {v5, v6, v7}
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12
12345
1234588
Graph
1
2
3
4
5
6
7
Procedure: DFS(4): EndP = { v1, {v1, v2, v3, v4, v5} } {v5, v6, v7}
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
12
12345
1234588
Graph
1
2
3
4
5
6
7
Procedure: DFS(3): End(No operation when w=5)P = { v1, {v1, v2, v3, v4, v5} } {v5, v6, v7}
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
1 1999988
Graph
1
2
3
4
5
6
7
Procedure: DFS(2): EndP = { } {v1, v2, v3, v4, v5} {v5, v6, v7}
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Demo: Gabow’s biconnected components algorithm
Data in memoryB and S: stack. I: array.B S I
1234567
9999988
Graph
1
2
3
4
5
6
7
Procedure: DFS(1): EndP = { } {v1, v2, v3, v4, v5} {v5, v6, v7}
Harold N. Gabow Path-based DFS for SCC and BCC
IntroductionStrong Components
Biconnected Components
ReviewHigh-Level AlgorithmGabow’s Algorithms
Correctness
In order to keep the completeness, the correctness is givenas follow.
Theorem (Correctness and complexity)
When BICONN(G) halts any edge {v, w} ∈ E belongs to thebiconnected component numbered min{I[v], I[w]}. The timeand space are both O(V + E).
Harold N. Gabow Path-based DFS for SCC and BCC