Ov er vie w

advertisement
Page 1
J. Maluszynski, IDA, Linköpings Universitet, 2004.
TDDB57 DALG – Lecture 13: Graphs, part II.
Page 2
e
if
(
c
iff
)
J. Maluszynski, IDA, Linköpings Universitet, 2004.
induced by
is not connected.
= subgraph of
J. Maluszynski, IDA, Linköpings Universitet, 2004.
[L/D p. 440–442]
and has more than one child in , or
f 3
TDDB57 DALG – Lecture 13: Graphs, part II.
4
no skipped edge joins a descendant
of f with a proper ancestor of b
cut vertex
Biconnectivity
c
e 5
Consider fault-tolerance in a communication network.
One node breaks down, can the other ones still communicate?
b
d
Overview
[L/D 12.2]
c
2 b
Some applications of DFS
a
e
Page 4
is a cutvertex of
it is not a root and
it has a child in , none of whose descendants
is connected with a proper ancestor of by a skipped edge.
1 a
is a cutvertex of a connected graph
b
d
cutvertex: a
A graph is biconnected if it has no cutvertices.
? How to check this?
TDDB57 DALG – Lecture 13: Graphs, part II.
it is the root of DFS tree
Checking biconnectivity of undirected graph
Topological sorting of directed acyclic graphs
J. Maluszynski, IDA, Linköpings Universitet, 2004.
Depth-First Search Tree and Cut Vertices
Page 3
Depth-First Search Tree
f 3
Visit:
a
b
f
c
e
Encountered:
a
a,b
a,b,f
a,b,f,c
a,b,f,c,e
a,b,f,c,e,d
a,b,f,c,e,d
6 d
TDDB57 DALG – Lecture 13: Graphs, part II.
Lemma:
2 b
c 4
e 5
d
Depth-First Search follows some edges by its recursive calls
and skips the other (target vertex already visited)
1 a
6 d
Pre-visit version of DFS
The vertices of with the followed edges make a tree . Why?
These followed edges are called tree edges, the other skipped edges.
-
-
'
+
!
"
$
%
#
&
!
#
'
2
!
'
&
#
<
%
"
5
+
=
C
D
F
E
G
>
/
%
!
5
?
@
@
B
=
A
5
+
:
(
I
(
2H
already visited
;
(
2H
+
2H
,
#
)
7
-
"
,
/
+
/
0
is empty
K
2H
)
I
!
'
"
+
J. Maluszynski, IDA, Linköpings Universitet, 2004.
J. Maluszynski, IDA, Linköpings Universitet, 2004.
#
initially,
/
@
=
Page 6
&
.
.
$
TDDB57 DALG – Lecture 13: Graphs, part II.
not yet encountered:
#
1
J. Maluszynski, IDA, Linköpings Universitet, 2004.
Page 5
-
#
!
(
):
recursively, return smallest depth encountered
Page 8
Checking Biconnectivity (2)
of
3
from
(
traverse
&
neighbor
: if none exists, the graph is biconnected.
[L/D Algorithm 12.4]
+
in DFS tree, and apply the lemma.
)
= depth of
(
4
true
,
skipped:
,
3
in
edge
(
(
+
*
false
"
;
vertex
&
any vertex in
0
has depth 1
TDDB57 DALG – Lecture 13: Graphs, part II.
2
2
%
more than one neighbor of
true
J. Maluszynski, IDA, Linköpings Universitet, 2004.
89:
89:
Page 7
TDDB57 DALG – Lecture 13: Graphs, part II.
Topological Sorting of a DAG: Implementation with DFS
-
,
Checking Biconnectivity (1)
Topological Sorting of a Directed Acyclic Graph (DAG)
Find cutvertices of
+
We could use depth-first search, where
Topological sorting:
Given a DAG , put its vertices in a sequence
such that if
is an edge of then
.
i.e., vertices in a linear order preserving the “arrow” ordering.
6
+
*
For all : maintain
TDDB57 DALG – Lecture 13: Graphs, part II.
/
Topological sort:
,
+
+
!
a
'
b, a, d, c, e
2H
Is this the only one?
'
c
2
e
+
*
2
)
)
2
"
Application: task scheduling, instruction scheduling
b
d
(
=
+
*
J
!
.
\
'
'
W
'
%
%
Z]^
(
X
J
J
"
5Y
'
!
\
/
%
X
.
&
&
&
Z[
"
2H
L
'
5Y
!
-
#
J
S
M
Z[
+
+
+
JM
#
R
R
)
J
T
*
J
+
:
J
\
J
Z]^
Z]^
N
\
I
O
M
.
J
I
\
\
X
)
X
5Y
5Y
.
J
J
0
*
)
&
Z[
#
(
*
Z[
&
P
#
#
!
1
!
%
,
&
S
)
O
M
*
+
)
S
O
M
T
3
J
T
false;
%
.
J
J
.
J
=
Page 9
(
true
neighbor of
O
TDDB57 DALG – Lecture 13: Graphs, part II.
Adjusting DFS to Topological Sort of DAGs
%
%
Q
.
/
/
U
V
V
%,
U
0
#
1
-
)
J. Maluszynski, IDA, Linköpings Universitet, 2004.
Download