0% found this document useful (0 votes)
9 views20 pages

30 DFS Applications

Uploaded by

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

30 DFS Applications

Uploaded by

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

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Graph Algorithms
DFS Applications

Dr. Shahbaz Khan


Department of Computer Science and Engineering,
Indian Institute of Technology Roorkee
[email protected]
DFS Tree

DFS Visit Time?


DFS Finish Time?

Types of Edges
● Undirected Graphs

● Directed Graphs

2
Applications

● Connected Components

● Articulation points and Biconnected Components [1973]

● Bridges and 2-edge connected components [1974]

● Strongly Connected Components [1972]

● Strong Articulation points*

● Strong Bridges*

*Giuseppe F. Italiano, Luigi Laura & Federico Santaroni, Finding Strong Bridges and Strong Articulation Points in Linear Time,
COCOA 2010.

3
Connected Components

An undirected graph is connected if there is a path between every pair of vertices


The maximum connected subgraphs of an undirected graph are its components.

b
d f
a
c e g

Brute Force Algorithm

Think of a brute force algorithm to compute


the components of a graph.

4
Connected Components

An undirected graph is connected if there is a path between every pair of vertices


The maximum connected subgraphs of an undirected graph are its components.
b
d f
Brute Force: a
c e g

Complexity:

5
Articulation points and Biconnected comp
Articulation point of a connected graph is a vertex whose deletion disconnects it.
An undirected graph is biconnected if there are at least two vertex disjoint paths
between every pair of vertices, or it does not have any articulation point.
The maximum biconnected subgraphs of an undirected graph are its biconnected
components, whose boundary nodes are the articulation points.
b
d f
a
c e g

Brute Force Algorithm

Think of a brute force algorithm to compute


the articulation points and the biconnected
connected components of a graph.

6
Articulation points and Biconnected comp
Properties: b
1- DFS forest has biCC as subtrees rooted d f
at articulation points a
c e g
2- No edge between child subtrees and ancestors
3- Root an articulation point if more than one subtree

d
e

f
c

7
Articulation points and Biconnected comp
Properties:
BiCC()
1- DFS forest has biCC as subtrees rooted for(forAll v in V){
at articulation points index = 1;
2- No edge between child subtrees and ancestors if(visit[v] == -1)
DFS(v);
3- Root an articulation point if more than }
one subtree a
DFS(vertex v){
b visit[v] = index++;
b low[v] = visit[v];
d f
a d forEach((v,w) in E){
c e g
e if(visit[w] == -1){
DFS(w);
low[v] = min(low[v],low[w]);
f if(visit[v] <= low[w])
Data Structures: c Mark v;
}
visit[x]: DFS visit time of x else
g
low[x]: Earliest DFS visit time reachable low[v] = min(low[v],visit[w]);
}
from subtree of x using a non-tree edge }

8
Articulation points and Biconnected comp
b
BiCC() d f
for(forAll v in V){
index = 1; a
c e g
if(visit[v] == -1)
DFS(v);
}

DFS(vertex v){
visit[v] = index++;
low[v] = visit[v]; a

forEach((v,w) in E){ b
if(visit[w] == -1){
DFS(w); d
low[v] = min(low[v],low[w]);
e
if(visit[v] <= low[w])
Mark v;
} f
else c
low[v] = min(low[v],visit[w]);
} g
}

9
Bridges and 2-edge Connected Comp

Bridge of a connected graph is an edge whose deletion disconnects it.


An undirected graph is 2-edge connected if there are at least two edge disjoint
paths between every pair of vertices, or it does not have any bridge.
The maximum 2-edge connected subgraphs of an undirected graph are its
2-edge connected components, whose boundary edges are the bridges.
b
d f
a
c e g

Brute Force Algorithm

Think of a brute force algorithm to compute


the bridges and the 2-edge connected
components of the graph.

10
Bridges and 2-edge Connected Components

Properties: b
1- DFS forest has biCC as subtrees rooted d f
at bridge vertices a
c e g
2- No edge between subtree and ancestors

e
d

f b

11
Bridges and 2-edge Connected Components
2eCC()
Properties: for(forAll v in V){
index = 1;
1- DFS forest has biCC as subtrees rooted if(vis[v] == -1)
at bridge vertices DFS(v);
}
2- No edge between subtree and ancestors
DFS(vertex v){
a visit[v] = index++;
low[v] = visit[v];
c
forEach((v,w) in E){
b e if(visit[w] == -1){
d
d f DFS(w);
low[v] = min(low[v],low[w]);
a f b
c e g }
else
g low[v] = min(low[v],visit[w]);
}
Data Structures:
visit[x]: DFS visit time of x if(vis[v] == low[v])
Mark (v,par(v));
low[x]: Earliest DFS visit time reachable Report unmarked subtree of v
from subtree of x using a non-tree edge }

12
Bridges and 2-edge Connected Components
2eCC()
for(forAll v in V){ b
index = 1; d
if(vis[v] == -1) f
DFS(v); a
c e g
}

DFS(vertex v){
visit[v] = index++;
low[v] = visit[v];

forEach((v,w) in E){
if(visit[w] == -1){ a
DFS(w);
low[v] = min(low[v],low[w]);
} c
else
e
low[v] = min(low[v],visit[w]); d
}
f b
if(vis[v] == low[v])
Mark (v,par(v)); g
Report unmarked subtree of v
}

13
Relationship

Articulation Points and Bridges

1- Does a graph having an articulation point,


necessarily has a bridge?
2- Does a graph having a bridge necessarily have
an articulation point?
3- Does a graph having two adjacent articulation
points necessarily has a bridge?

14
Strongly Connected Components

An directed graph is strongly connected if for any pair of vertices there are
directed paths from each to the other.
The maximum strongly connected subgraphs of an undirected graph are its
strongly connected components.

b d

a f
c e

Brute Force Algorithm

Think of a brute force algorithm to compute


the strongly connected components of a graph.

15
Strongly Connected Components

An directed graph is strongly connected if for any pair of vertices there are
directed paths from each to the other.

The maximum strongly connected subgraphs of an undirected graph are its


strongly connected components.
b d
PROPERTY: SCCs of a connected graph form a DAG
a f
c e

Brute Force:
g

Complexity:

16
Strongly Connected Components
SCC()
b d
for(forAll v in V){
index = 1;
if(visit[v] == -1) a f
c e
DFS(v);
}
g
DFS(vertex v){
Push v in S;

visit[v] = index++;
low[v] = visit[v];
b
forEach((v,w) in E){
if(visit[w] == -1){ d
DFS(w);
low[v] = min(low[v],low[w]); f
c
}
else if(w in S) g a
low[v] = min(low[v],visit[w]);
}
e
if(visit[v] == low[v])
Report SCC = Pop S upto v;
}

19
Topological Order

DAG of Strongly Connected Components

Can we determine the topological order of


the DAG of SSCs using the same algorithm

20

You might also like