Академический Документы
Профессиональный Документы
Культура Документы
Summer 2004
Graph Algorithms:
BFS, DFS, Articulation Points
Larry Ruzzo
BFS(v)
BFS(v)
1
4
6
9
Exercise: modify
code to number
vertices & compute
level numbers
3
BFS analysis
5
11
12
10
8
13
4
6
9
5
11
12
13
10
Depth-First Search
DFS(v)
1
Global Initialization:
mark all vertices v "undiscovered via v.dfs# = -1
dfscounter = 0
10
3
DFS(v)
v.dfs# = dfscounter++ // mark v discovered
for each edge (v,x)
if (x.dfs# = -1)
// tree edge (x previously undiscovered)
DFS(x)
else
// code for back-, fwd-, parent,
// edges, if needed
9
// mark v completed, if needed
DFS(v)
13
6
4
5
10
Like BFS(v):
(through previously unvisited vertices)
10
3
11
12
8
13
9
BUT
4
5
12
11
11
12
Non-tree edges
13
14
Articulation Points
Exercise
1
2
10
3
11
7
12
13
6
4
15
u
x
16
Articulation Points:
the "LOW" function
If removal of u
does NOT
separate x,
there must be
an exit from
x's subtree.
How? Via back
edge.
triv
ial
DFS(v) for
Finding Articulation Points
Properties of
DFS Vertex Numbering
then
?
dfs#(u)
dfs#(v).
19
Articulation Points
Articulation Points
A
B
C
D
F
I
K
E
G
H
J
L
M
2 B
3
4
5
6
7
21
F
I
K
A 1
C
8
D
9
G
11
E
H 10
J
L 12
M 13