Applications of DFS: Articulation Points and Biconnected Components These slides are based on the...

17
Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451 at the University of Maryland. The Copyright notice is as follows: Copyright, David M. Mount, 2008 Dept. of Computer Science, University of Maryland, College Park, MD, 20742. These lecture notes were prepared by David Mount for the course CMSC 451, Design and Analysis of Computer Algorithms, at the University of Maryland. Permission to use, copy, modify, and distribute these notes for educational purposes and without fee is hereby granted, provided that this copyright notice appear in all copies.

Transcript of Applications of DFS: Articulation Points and Biconnected Components These slides are based on the...

Page 1: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

Applications of DFS: Articulation Points and Biconnected

Components

These slides are based on the Lecture Notes by David Mount for the course CMSC 451 at the University of Maryland. The Copyright notice is as follows:Copyright, David M. Mount, 2008 Dept. of Computer Science, University of Maryland, College Park, MD, 20742. These lecture notes were prepared by David Mount for the course CMSC 451, Design and Analysis of Computer Algorithms, at the University of Maryland. Permission to use, copy, modify, and distribute these notes for educational purposes and without fee is hereby granted, provided that this copyright notice appear in all copies.

Page 2: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

Articulation Point

• Let G = (V,E) be a connected undirected graph.

Articulation Point: is any vertex of G whose removal results in a disconnected graph.

Page 3: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

Articulation Point

Articulation Point: is any vertex of G whose removal results in a disconnected graph.

Page 4: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

Biconnected components

• A graph is biconnected if it contains no articulation points.

• Two edges are cocyclic if they are equal or if there is a simple cycle that contains both edges. (Two different ways of getting from one edge to the other)– This defines an equivalence relation on the edges of the graph

• Biconnected components of a graph are the equivalence classes of cocyclicity relation

Page 5: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

Biconnected components

• A graph is biconnected if and only if it consists of a single biconnected component– No articulation points

Page 6: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

Articulation points and DFS

• How to find articulation points?– Use the tree structure provided by DFS

– G is undirected: tree edges and back edges (no difference between forward and back edges, no cross edges)

• Assume G is connected

Page 7: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

internal vertex u

• Consider an internal vertex u – Not a leaf,

– Assume it is not the root

• Let v1, v2,…, vk denote the children of u– Each is the root of a subtree of DFS

– If for some child, there is no back edge from any node in this subtree going to a proper ancestor of u, then u is an articulation point

u

Here u is an articulation point

Page 8: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

internal vertex u

• Here u is not an articulation point– A back edge from every subtree of

u to proper ancestors of u exists

u

Page 9: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

What if u is a leaf

• A leaf is never an articulation point• A leaf has no subtrees..

Page 10: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

What about the root?

• the root is an articulation point if an only if it has two or more children.– Root has no proper ancestor

– There are no cross edges between its subtrees

This root is an articulation point

Page 11: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

How to find articulation points?

• Keep track of all back edges from each subtree?– Too expensive

• Keep track of the back edge that goes highest in the tree (closest to the root)– If any back edge goes to an ancestor of u, this one will.

• What is closest to root?– Smallest discovery time

Page 12: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

Define Low[u]

• Low[u]: minimum of d[u]

and

{d[w] | where (v,w) is a back edge and v is a (nonproper) descendent of u.}

Page 13: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

Computing Low[u]

• Initialization: Low[u] = d[u]

• When a new back edge (u, v) is detected: Low[u] = min( Low[u], d[v])

• Tree edge (u, v):

Low[u] = min(Low[u], Low[v])

Page 14: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

• Once Low[u] is computed for all vertices u, we can test whether a nonroot vertex u is an articulation point

• u is an articulation point iff it has a child v for which Low[v] >= d[u]

Page 15: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

DFS(G)

for each (u in V) do

color[u] = white

pred[u] = NIL

time = 0

for each (u in V) do

if (color[u] == white)

findArticPts(u)

Page 16: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

findArticPts(u) //vertex u is just discovered

color[u] = gray

Low[u] = d[u] = ++time

for each (v in Adj[u]) do {

if (color[v] == white) then { //(u, v) is a tree edge

pred[v] = u

findArticPts(v)

Low[u] = min(Low[u], Low[v]) //update Low[u]

if (pred[u] == NIL) {//u is root

(if v is u’s second child) add u to set of articulation

points

}

else if (Low[v] >= d[u]) // if there is no back edge to an ancestor of u

add u to set of articulation points

}

else if (v != pred[u]) //(u, v) is a back edge

Low[u] = min(Low[u], d[v]) //this back edge goes closer to the root

}

Page 17: Applications of DFS: Articulation Points and Biconnected Components These slides are based on the Lecture Notes by David Mount for the course CMSC 451.

a

j

ie

c

b

g

d h

f

a

b e

c

d

g

f

h

i

j

Low = 1

1

1

13

3

3

8

8

8

d=1

2

3

8

4

5

6

7

9

10