Upload
others
View
7
Download
0
Embed Size (px)
Citation preview
5. Biconnected Components of A Graph
If one city’s airport is closed by bad weather, can you still fly between any other pair of cities? If one computer in a network goes down, can a message be sent between any other pair of computers?
If any one vertex (and edges incident with it) is removed from a connected graph, is the remaining subgraph still connected?
1
G
I
E
C
F
B
A D
H J F
A D
H J
E
F
E
C B
G
I
B
(a) graph. (b) Its biconnected components
Def’n: Let G=(V, E) be a connected, undirected graph.
A vertex aV is said to be an articulation point
if there exist vertices v and w such that
(1) v, w and a are distinct
(2) Every path between v and w must contain a.
Alternatively, a is an articulation point of G
if removing a splits G into two or more parts. subgraphs
2
Def’n: A connected graph G =(V, E) is said to be biconnected
if and only if it has no articulation points.
G1 G2 G3
Which of the above are biconnected?
Def’n: Let G' = (V', E') be a biconnected subgraph of a graph G = (V, E).
G' is said to be a biconnected component of G if G' is maximal
i.e., not contained in any other biconnected subgraph of G.
Examples are shown in the previous page !!!
3
G = (V, E)
Two edges e1 and e2 in E are said to be related, i.e., (e1, e2) ∈ R
if e1 = e2 or if there is a cycle containing both e1 and e2.
(e, e) R e E
(e1 , e2) R and (e2 , e3) R (e1 , e3) R
(e1 , e2) R (e2 , e1) R why ?
Observation
e1 e2 e3 Why transitivity?
4
An equivalence relation on E partitions E into equivalence classes !!!
Each subgraph consisting of the edges in an equivalence class and
the incident vertices form a biconnected component !!!
Can you prove it ? Homework.
5
Gi
Lemma: For 1 i k , Let Gi =(Vi , Ei) be the biconnected components of a
connected undirected graph G = (V, E).
Then
(1) Gi is biconnected for each 1 i k ,
(2) For all i j , Vi Vj contains at most one vertex. (3) a is an articulation point of G
if and only if a Vi Vj for some i j [ proof ]
(1) Trivial why ?
(2) suppose that two distinct vertices v and w are in Vi Vj , i j
v
w
C1
Gj C2
Why?
(3) x
a
y
() () x
a
y
v
w
Homework.
6
A B
C
D
E
A B
C
D
E
F
A
B
C
D
E
A
B
C
D
E
F
A is not an articulation point A is an articulation point
Can you now characterize an articulation point when A is the root ?
7
A
B
C
D
E
F
G H
I
A
B
C
D
E F
G
H
I
Can you characterize D ?
8
An articulation point v in a depth-first search tree.
Every path from root to w passes through v !!!
v
w
root
9
Theorem : Let G = (V, E) be a connected, undirected graph and let T = (V, ET) be a depth first spanning tree for G. Vertex a is an articulation point of G if and only if one of the following is true: (1) a is the root and a has two or more sons. (2) a is not the root and for some son s of a, there is no back edge between any descendant of s ( including s itself ) and a proper ancestor of a.
10
[proof] i) The root is an articulation point if and only if it has two or more sons.
()
()
x y
x y a
a
a
x y
a
x y
why? a
x y
s
11
(ii) Vertex a is not the root : Vertex a is an articulation point if and only if there exists no back edge between any descendant of s to a proper ancestor of a, where s is a son of a.
a
s
12
()
x y a
y x
Either x or y is a proper descendant of a !!!
a
why ?
WLOG, let x be a proper descendant of a a
x x y
s
a
s This is not possible.
Why ? Only this
Two cases: (1) (2)
x
a
x
a
s s back edge no back edge
13
case (2) : back edge
Suppose that y is not a (proper) descendant of a.
Thus, y must be a (proper) descendant of a.
() Easy, Exercise
x
a
y
w'
w
a
x y
This is not possible. s s’
s
14
v
w
z
An algorithm for finding all biconnected components of a graph G = (V, E)
biconnected component
z
x y
v x y
15
How to detect an articulation point ?
How to report a biconnected component ?
Assumption
Depth First Search
16
3
Depth First Search number
G =(V, E)
Any relation between DFS numbers and articulation points ?
B
D
E
A
C
F
1
2
4 5
6
Vertices DSF#
A 1
B 2
C 3
D 6
E 5
F 4
B
D
E
A
C
F
17
w
B
D
E
A
C
F
1
2
3
4 5
(a,b) a b
Tree edge : (a,b) a < b
Back edge : (a,b) a > b
If there is a back edge from x
to a proper ancestor w of v,
then w is reachable from v.
6
v
x
18
BACK[v] = w
v can back to w by following
(1) tree edges (2) back edges BACK[v]:= min{DFSNUMBER(v), min{w| (x,w) is a back edge, x is a descendant of v,
and w is an ancestor of v.}}
How far can a vertex back to ancesters in the DFS tree ?
v
w
x
19
Initially (when v is first visited),
BACK[v] = DFSNUMBER[v]
why?
Now, how to update BACK[v] ?
(i) v w (back edge)
(ii) v w (backing up to v)
case(i) BACK[v]:= min{BACK[v], w} : back edge
why ? case(ii) BACK[v]:= min{BACK[v], BACK[w]} : back up to v why ?
v
w
w
case (i)
case (ii)
20
why ?
How to detect an articulation point ?
v BACK[w] when w v (backing up to v).
v
w i) backing up to v
ii) v BACK[w]
21
How to report ?
Well, …….
A set of edges.
22
v
w
z
W A
B
y
r
a b
(v, w)
(y, v)
(r, z)
(y, a)
(z, y)
W
A
Edge Stack
when v is reached, pop edges until (v, w) is reached
yꞌ
23
A
D
F
E
B
C
J
H
G
I
1
2
3
4
5
6 8
7
9
10
(a) The complete depth- first search tree.
A
D
F
1/1
2/2
3/1
(b) Proceed forward ; initialize values of back ; Detect back edge FA ; update back[F] ;
E
C
4/4
5/5
6/4 (c) Continue forward ; Detect back edge CE ; update back[C]
B
C
5/4
6/4
4/4 B
5/4 7/7
8/5
G
I
B 5/4 7/5
8/5
G
I
E
B
C
5/4
4/4
(d) back[C]
begin
mark v "old";
DFSNUMBER[v] COUNT;
COUNT COUNT + 1;
BACK[v] DFSNUMBER[v];
for each vertex w on L[v] do Stack edges, here
if w is marked "new" then
begin
add(v, w) to T;
FATHER[w] v
SEARCHB(w)
if BACK[w] DFSNUMBER[v] then a
biconnected component has been found ; Pop, here
BACK[v] MIN(BACK[v], BACK[w])
end
else if w is not FATHER[v] then
BACK[v] MIN(BACK[v], DFSNUMBER[w]) end
end
procedure SEARCHB(v);
Report
O(|E|)
Why ?
25
T := Ø ;
for all v in V do
mark v as "new"
end
count := 1 ;
for all "new" vertex v in V do
SEARCHB(v) |V| + (|E1| + |E2| + …) = |V| + |E|
end
Theorem : Algorithm Bicomp correctly finds the biconnected
components of G = (V, E) in O(|E| + |V|) time.
[proof ]
See the next page.
Algorithm : Bicomp.
O(|V|)
G = (V, E) : not connected
G1 G2 G3
Spanning forest.
G1
G2
G3 G4
26
(i) Time complexity O(|V| + |E|)
(ii) Correctness Root ?
Even if the root is not an articulation point,
it can be treated as an articulation point !!!
why ?
The biconnected component containing the root
is emiting from the root.
27
By induction on the # of biconnected components in G, we prove that our algorithm correctly
detects all articulation points and reports their corresponding biconnected components.
How to detect:
(i) w v (SEARCHB(w) is completed)
(ii) v BACK[w]
How to report:
Popping up the edges above (v, w) on EDGE STACK
Popping up the edges above (v, w) on EDGE STACK
v
w
(b = 1) Trivial
why ?
Depth First Search !!!
In this case, v must be the root !!! why ?
(b = i) Assume the induction hypothesis.
(b = i+1) (v,w)
b-1=i
28
K-connectivity
k = 1 connectivity
k = 2 bi-connectivity
k = 3 tri-connectivity
k = 4
no known efficient algorithms
29
6. Strongly Connected Components of a Digraph
Def'n : Let G = (V, E) be a directed graph. We can partition V into equivalent classes Vi, 1 i r, such that vertices v and w are
equivalent if and only if there are paths from v to w and w to v.
Let Ei, 1 i r, be the set of edges connecting the vertices
in Vi. The graph Gi = (Vi, Ei) is called a strongly connected
component of G. A graph is said to be strongly connected
if it has only one strongly connected component.
1
2 3
4
5 6
7
8
9 G=(V, E)
G1
G2
G3
30
1
2 3
4
5 6
7
8
9 G=(V, E)
G1
G2
G3 R = {(v, w) | there exist paths from v to w and w to v}
R is an equivalence relation !
why? Homework
R partitions V into a set of equivalence classes.
31
A
D
F
E
B
C
J
H
G
I
K
A
D
F
E
B
C
J
H
G
I
K
(a) A digraph (b) Its strong components.
The condensation of the digraph
32
G = (V, E)
A Weakly Connected Component
(Network Flow)
33
How to find the strongly connected components of a graph ?
Assumption : Depth First Search
tree edge
descendant edge
cross edge
back edge
first visited
backing up to v
backing up from v
34
v1
v8 v7
v6
v4
v3
v2
v5
v10
v9 v12
v11
v15 v14
v13
v18 v17
v16
G = (V, E)
v5 v6
v11
v4
v1
v2
v3
v7
v8
v16
v17
T = (V, ET)
v18
Spanning Forest
v10
v12
v9
v13
v14
v15
1
2
3
4
5 6
7
8
9
10
11
12
13
14
15 16
17 18
How to characterize the root of the DSF subtree for each strongly connected component ?
35
Lemma : Let Gi = (Vi, Ei) be a strongly connected component of a directed graph
G = (V, E). Let T = (V, ET) be a depth-first search spanning forest of G.
Then the vertices of Gi together with the edges which are common to both
Ei and ET form a subtree of the spanning forest T.
[ proof ]
Gi =(Vi, Ei)
Take any pair of vertices v,w Vi
Depth first number
WLOG, let v < w.
In Gi, v w
P
why ?
x = min{ y| y is in P }
Note : x may be v itself.
v w
36
w is a descendant of x !!!
Now, all vertices between x and w are also descendants of x.
why ?
DFS !!!
Since x v < w, v is also a descendant of x.
Any pair of vertices v, w in Gi have a common ancestor x in T.
Why ?
r min{ y| y is a common ancestor of vertices in Gi}
In T,
p
x
Once P reaches a descendant of x in the DFS forest T,
it cannot leave the subtree of x !!! why?
v x w
In Gi,
v w
P
x
x ≤ v < w
y
y
37
r min{ y| y is a common ancestor of vertices in Gi}
For each vertex u in Gi , r ≤ u and r → u and u → r . ∴ u is in the subtree of r .
For each vertex u Gi , every vertex u' on the path from r to u in the subtree of r
is also contained in Gi
why? r u
'u
∴ r must be the root of the spanning subtree for strongly connected component Gi
iGu
r
u'
u
iGu
u' is in
the subtree of r
38
v4 v5
v7
v6 v9
v8
v1
v2
v3 G = (V, E)
v5
v4
v1
v2
v3
1
2
3
4
5
v6
v7
v8
6
7
8
v9 9
(r1, r2, r3, ····, rk) the sequence of roots for strongly connected components 4 6 1 such that the DFS of each of these roots is terminated.
39
(r1, r2,····, rk)
Observation
i < j Either rj is the root of a right subtree of ri or a proper ancester of ri. why ?
40
Lemma : For each i, 1 i k, Gi consists of those vertices
which are descendant of ri but are contained in none of G1, G2,····, Gi-1.
[proof] The root rj for j > i cannot be a descendant of ri,
since the call of SEARCH(rj) terminates after SEARCH(ri).
(r1, r2, r3, ···, ri-1, ri, ri+1, ···, rk)
already
reported j > i
rj is the root of
a right subtree or a proper ancestor.
41
w
v
r
LOWLINK[v] = min { DFSNUMBER(v) min{ w| there is a cross or back edge (x, w)
from a descendant x of v to a vertex w
that is not a descendant of v ,
and the root of the strongly
connected component
containing w is an ancestor of v } }
LOWLINK[v] v
Why ?
w
42
x
Lemma : Let G = (V, E) be a directed graph. A vertex v is the root of a strongly connected component if and only if LOWLINK[v] = v.
[proof]
( ) Suppose that v is the root of a strongly connected component of G.
By definition of LOWLINK, LOWLINK[v] v for all v V. Suppose that LOWLINK[v] < v. Then, there are vertices w and r such that [1] w is reached by a cross or back edge from a descendant of v. [2] r is the root of the strongly connected component containing w.
[3] r is an ancestor of v.
[4] w < v
r and v must be in the same strongly connected component !!!
why ? From [1], [2], and [3].
[2] r is an ancestor of w r w
[4] r w < v r < v
[3] r is a proper ancestor of v.
v is not the root of a strongly connected component. #
LOWLINK[v] = v.
r v
w v
r
x
w
43
w
( ) Now, suppose that LOWLINK[v] = v. Assume that v is not the root of the strongly connected component. Then, there is some proper ancestor r of v, which is the root, i.e.,
The path P goes from v to w to r.
There also exists a path from r to v. Why?
v and w are in the same strongly connected component.
LOWLINK[v] w < v. #
v
r
w
Moreover, there is a path P from v to r . Why? Consider the first edge of P from a descendant of v to a vertex w that is not a descendant of v. Then, w < v why ?
P P
44
w
How to compute LOWLINK[v]
LOWLINK[v] := v
LOWLINK[v] = min{ LOWLINK[v], w }
LOWLINK[v] = min{ LOWLINK[v],
LOWLINK[w] }
w
w
v
v v
w
first visited
a back edge or a cross edge
backing up to v v
w
45
if the root of the strongly connected component containing w is an ancestor of v.
How to check this ?
v
s' s
backing up from v
How to report a strongly connected component
LOWLINK[v] = v
f
46
y
z
v LOWLINK[v] = v
x
y z
g
x
g
v
47
q
How to check that the root of the strongly connected component
containing w is an ancestor of v?
What if w is on the stack ?
v and w have a common ancestor !
Why ?
r
v t
w u
q
r
v t
w u
u
v
w
t
q
r
…
u
v
q
…
w ∈ stack w ∈ stack
48
Procedure SEARCHC(v): begin mark v "old"; DFSNUMBER[v] COUNT; COUNT COUNT + 1; O(|V|) LOWLINK[v] DFSNUMBER[v]; push v on STACK; for each vertex w on L[v] do O(|E|) if w is marked "new" then begin SEARCHC(w); LOWLINK[v] MIN(LOWLINK[v], LOWLINK[w]) end back edge or cross edge else {not new} if DFSNUMBER[w] < DFSNUMBER[v] need a table and w is on STACK then LOWLINK[v] MIN(DFSNUMBER[w], LOWLINK[v]) end if LOWLINK[v] = DFSNUMBER[v] then begin repeat begin pop x from top of STACK; print x end until x=v; print "end of strongly connected component" end end
49
Algorithm : (Strongly connected components of a directed graph)
procedure StrongCC
begin
count := 1;
for all v in V do
mark v "new" O(|V|)
end
STACK := Ø
while there exists a vertex v marked "new" do
SEARCHC(v) O(|E|)
end.
end
Optimal !!!
O( |V| + |E| )
50
Theorem : "StrongCC" correctly finds the strongly connected
components of G in O(|V| + |E|) time.
[proof]
Time complexity : Already shown
Correctness : ( By induction on # of strongly connected components)
"The algorithm correctly detects all the roots of the
subtrees for the strongly connected components and
reports these components."
Exercise.
51
52
• November 18 (Friday)
• 10:00 ~ 11:00 class A
14:00 ~ 15:00 class B
• Room #4443
(Oh Sang-su lecture room)
Lecture Schedule