Sie sind auf Seite 1von 31

Data Structures and Algorithms

(CS210/ESO207/ESO211)
Lecture 23
Novel application of DFS traversal:
An O(m+n) time algorithm for articulation points in a graph
1
Outline of the lecture
Refreshing DFS traversal

Refreshing the problem of articulation points

Relationship between articulation points and DFS traversal
Key insight and ideas

Recursive nature of DFS traversal
(for efficient implementation of the ideas)

2
Depth First Search (DFS) traversal
3
A recursive algorithm for traversing graphs
DFS traversal of G
DFS(v)
{ Visited(v) true;
For each neighbor w of v
{ if (Visited(w) = false)
{ DFS(w) ;

}

}
}

DFS-traversal(G)
{
For each vertex v V { Visited(v) false }
For each vertex v V { If (Visited(v ) = false) DFS(v) }
}

4
..;
..;
You will need to add only a few extra
statements here to obtain efficient
algorithms for a variety of problems.
DFN[v] dfn ++;
dfn 0;
Insight into DFS through an example














5
z
y
c
d
b
f
g
h
u
w
v
r
s
0 1
2
3
4
5
6
7
8
9
10
11
12
DFS(v) computes a tree rooted at v












6
z
y
c
d
b
f
g
h
u
w
r
s
v
A DFS tree rooted at v



Question:
Is there anything unique about a DFS tree ?
Answer: yes.


Every non-tree edge is between an ancestor
and descendant in the DFS tree.




7










8
u
x
y
It can never happen
Every non tree edge is between ancestor and a descendant
of DFS tree
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.

9
Remember the following picture for DFS
traversal





non-tree edge back edge
10
A novel application of DFS traversal
11
Computing all articulation points in a graph G















No.
The removal of any of {v,f,u} can destroy
connectivity.

v,f,u are called the articulation points of G.
12
z
y
c
d
b
f
g
h
u
w
v
r
s
Does the graph remain
connected even after removal of
any single vertex ?
A formal definition of articulaton point
Definition: A vertex x is said to be articulation point if there exist two distinct vertices
u and v such that every path between u and v passes through x.







Observation: A graph is biconnected if none of its vertices is an articulation point.

AIM:
Design an algorithm to compute all articulation points in a given graph.
13
v
u
x
Articulation points and DFS traversal
14
Key insight and ideas
Some observations






Question: Can a leaf node be an a.p. ?
Answer: Never

15
Some observations






Question: Necessary condition for the root to be an a.p. ?
Answer: root must have more than one child in the DFS tree.
Question: Is this condition sufficient as well ?
Answer: Yes.

The only case left : internal nodes (other than the root node) in the DFS tree ?
AIM:
To find necessary and sufficient conditions for an internal node to be articulation point.

16
v
u
x
How will an internal node x look like in DFS tree ?










17
x
root
T1
At least one of u and v
must be descendant of x.
Where will u and v
be relative to x?
Case 1: Exactly one of u and v is a descendant of x in DFS tree










18
x
u
v
root
w
y
No back edge from
T1 to ancestor of x
T1
uwyv :
a u-v path not passing through x
Case 2: both u and v are descendants of x in DFS tree










19
x
root root
u
v
Can u and v belong to
T1 simultaneously?
T1
Case 2: both u and v are descendants of x in DFS tree










20
x
root
u v
w
q
y
z
T1 T2
At least one of T1 and
T2 have no back edge
to ancestor of x
uwzyqv :
a u-v path not passing through x
Necessary condition for x to be articulation point












Necessary condition:
x has at least one child y s.t. there is no back
edge from subtree(y) to ancestor of x.

Question: Is this condition sufficient also?
Answer: yes.

21
x
root
y
u
v
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 root has more than one child.
For any internal node ??

Theorem1 : An internal node x is articulation point if and only if it has a
child y such that there is no back edge from subtree(y) to any ancestor of x.


22
Efficient algorithm for Articulation points
23
Exploiting recursive nature of DFS
Starting point
Theorem1 : An internal node x is articulation point if and only if it has a child y such
that there is no back edge from subtree(y) to any ancestor of x.

A new function
High_pt(v):
DFN of the highest ancestor of v to which there is a back edge from subtree(v).

Question: Can we express Theorem 1 in terms of High_pt ?
Answer: Yes

A node x is articulation point iff it has a child, say y, such that High_pt(y) dfn(x).



24
Towards an O(m+n) time algorithm



In order to compute all articulation points of a graph G=(V,E) , it suffices to
know High_pt(v) for each v in V.

So our aim is to compute High_pt(v) for each v in V efficiently so that overall
time complexity is O(m+n).

For this we take a closer look at High_pt(v).




25
A closer look at High_pt(v)










Question: Can we express High_pt(v) in terms of
its children and proper ancestors?
26
v
root
A closer look at High_pt(v)










Question: Can we express High_pt(v) in terms of
its children and proper ancestors?

High_pt(v) =
min
?
?


27
v
root
If w=child(v)
If w = proper
ancestor of v
(v,w) E
High_pt(w)
DFN(w)
Fully internalize the above equation
and then only proceed.
The novel algorithm
The algorithm will output an array AP[] such that
AP[v]= true if and only if v is an articulation point.
28
Algorithm for articulation points in a graph 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) }
}

29
..;
..;
Parent(w) v;
AP[v] false
What statements should we write here so
that at the end of DFS(v),
We have computed High_pt(v)
Determined if v is articulation point and
computed AP[v] accordingly.
High_pt[v] ;
..;
Algorithm for articulation points in a graph 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) }
}

30
..;
..;
Else if (parent(v) w)
High_pt(v) min(DFN(w), High_pt(v))
High_pt(v) min(High_pt(v), High_pt(w));
Parent(w) v;
AP[v] false
High_pt[v] ;
..;
If High_pt(w) DFN[v] AP[v] true
Conclusion




Theorem2 : For a given graph G=(V,E), all articulation points can be
computed in O(m+n) time.


31

Das könnte Ihnen auch gefallen