Lec26 DFS II
Lec26 DFS II
(ESO207)
Lecture 26
• Depth First Search (DFS) Traversal
• DFS Tree
• Novel application: computing biconnected components of a graph
1
DFS traversal of G
DFS(v)
{ Visited(v) true; DFN[v] dfn ++;
For each neighbor w of v
{ if (Visited(w) = false)
{ DFS(w) ;
……..;
}
……..;
}
}
DFS-traversal(G)
{
dfn 0;
For each vertex vϵ V { Visited(v) false }
For each vertex v ϵ V { If (Visited(v ) = false) DFS(v) }
}
2
Depth First Numbering (DFN)
DFN[x] :
y v The number at which x gets visited during DFS
1 0
traversal.
10 w
f 2
3
b
4h 12 11 d
g
5 r
u
8
6 9z
s 7
c
3
DFS tree
4
DFS(v) computes a tree rooted at v
y v
Can
Is any tree
a DFS rooted tree
unique
be obtained through
for a graph ?
w
f DFS ?
b
h d No
No
g
u r
z
s
c
5
How will an edge appear in DFS traversal ?
• as a tree-edge.
No
6
How will an edge appear in DFS traversal ?
x
y
7
How will an edge appear in DFS traversal ?
x
y
8
How will an edge appear in DFS traversal ?
y v
w
f
b
h d
g
x
y
z
s
c
9
How will an edge appear in DFS traversal ?
A short proof:
Let (x,y) be a non-tree edge.
Let x get visited before y.
Question:
If we remove all vertices visited prior to x, does y still lie in the connected
component of x ?
Answer: yes.
DFS pursued from x will have a path to y in DFS tree.
Hence x must be ancestor of y in the DFS tree.
10
Always remember
the following picture for DFS traversal
11
A novel application of DFS traversal
12
Definition: A connected graph is said to be biconnected
if there does not exist any vertex whose removal disconnects the graph.
13
Is this graph biconnected ?
y v
w No.
f
b
h d
g
u r
z
s
c
14
A trivial algorithms for checking
bi-connectedness of a graph
15
An O() time algorithm
16
An O() time algorithm
17
This graph is NOT biconnected
y v
w
f
b
h d
g
The removal of any of {v,f,u} can destroy
u r connectivity.
18
A formal definition of articulaton point
u x v
AIM:
Design an algorithm to compute all articulation points in a given graph.
19
Articulation points and DFS traversal
20
Some observations
v
Question: When can a leaf node be an a.p. ?
Answer: Never
21
Some observations
v
Question: When can a leaf node be an a.p. ?
Answer: Never
22
Some observations
v
Question: When can a leaf node be an a.p. ?
Answer: Never
23
Some observations
u x v
AIM:
To find necessary and sufficient conditions for an internal node to be articulation point.
24
conditions for an internal node to be articulation
point.
root
25
Case 1: Exactly one of u and v is a descendant of x in DFS tree
root
v
y u—w—y—v :
Can there be a a u-v path not passing through x
back edge from
T1 to ancestor of
x?
x
No
u
w
T1 26
Case 2: both u and v are descendants of x in DFS tree
root
No T1 27
Case 2: both u and v are descendants of x in DFS tree
root
z u—w—z—y—q—v :
a u-v path not passing through x
y
At least one of T1 and
T2 have no back edge x
to ancestor of x
u v
w q
T1 T2 28
Necessary condition for x to be articulation point
root
Necessary condition:
x has at least one child y s.t.
there is no back edge
v from subtree(y) to ancestor of x.
x
Is this condition
u y sufficient also ?
yes.
29
Articulation points and DFS
Let G=(V,E) be a connected graph.
Perform DFS traversal from any graph and get a DFS tree T.
• No leaf of T is an articulation point.
• root of T is an articulation point if and only if it has more than one child.
• For any internal node … ??
30
Efficient algorithm for Articulation points
Use Theorem 1
Exploit recursive nature of DFS