0% found this document useful (0 votes)
43 views31 pages

Data Structures and Algorithms Data Structures and Algorithms

1) The document discusses depth first search (DFS) traversal and its applications. 2) It describes how DFS traversal works and defines key terms like DFS tree, discovery finishing numbers (DFN), and tree vs non-tree edges. 3) A novel application of DFS traversal discussed is using it to efficiently determine if a graph is biconnected by identifying articulation points, which are vertices whose removal would disconnect the graph. The algorithm exploits relationships between articulation points and the DFS tree representation.

Uploaded by

Osho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views31 pages

Data Structures and Algorithms Data Structures and Algorithms

1) The document discusses depth first search (DFS) traversal and its applications. 2) It describes how DFS traversal works and defines key terms like DFS tree, discovery finishing numbers (DFN), and tree vs non-tree edges. 3) A novel application of DFS traversal discussed is using it to efficiently determine if a graph is biconnected by identifying articulation points, which are vertices whose removal would disconnect the graph. The algorithm exploits relationships between articulation points and the DFS tree representation.

Uploaded by

Osho
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Data Structures and Algorithms

(CS210A)

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
DFN number

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

A DFS tree rooted at v

5
How will an edge appear in DFS traversal ?

• as a tree-edge.

If the edge is a non-tree edge :

• Edge between ancestor and descendant in


DFS tree.

any other possibility ?

No

6
How will an edge appear in DFS traversal ?

It can never happen

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

non-tree edge  back edge

This is called DFS representation of the graph.


It plays a key role in the design of every
efficient algorithm.

11
A novel application of DFS traversal

Determining if a graph G is biconnected

12
Definition: A connected graph is said to be biconnected
if there does not exit any vertex whose removal disconnects the graph.

Motivation: To design robust networks


(immune to any single node failure).

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
•  
• For each vertex v, determine if G\{v} is connected
(One may use either BFS or DFS traversal here)

Time complexity of the trivial algorithm : O()

15
An O() time  algorithm

A single DFS traversal

16
An O() time  algorithm

• A formal characterization of the problem.


(articulation points)

• Exploring relationship between articulation point & DFS tree.

• Using the relation cleverly to design an efficient 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.

z v,f,u are called the articulation points of G.


s
c

18
A formal definition of articulaton point

•  
Definition: A vertex x is said to be articulation point if
u,v different from x
such that every path between u and v passes through x.

u x v

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.

19
Articulation points and DFS traversal

Don’t Focus on the graph. Instead,


focus on the DFS tree representation of the graph.

20
Some observations

v
Question: When can a leaf node be an a.p. ?
Answer: Never

Question: When can root be an a.p. ?

21
Some observations

v
Question: When can a leaf node be an a.p. ?
Answer: Never

Question: When can root be an a.p. ?

22
Some observations

v
Question: When can a leaf node be an a.p. ?
Answer: Never

Question: When can root be an a.p. ?


Answer: Iff it has two or more children.

23
Some observations

u x v

AIM:
To find necessary and sufficient conditions for an internal node to be articulation point.

How will x look like


in DFS tree ?

24
conditions for an internal node to be articulation
point.
root

Where will u and v


be relative to x ?
At least one of u and v
must be descendant of x. x

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

Can u and v belong to


T1 simultaneously? v u

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 … ??

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.

30
Efficient algorithm for Articulation points

Use Theorem 1
Exploit recursive nature of DFS

Ponder over it before


31
tomorrow’s class 

You might also like