19
Connectivity 1 Connectivity and Biconnectivity • connected components • cutvertices • biconnected components

Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Embed Size (px)

Citation preview

Page 1: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 1

Connectivity and Biconnectivity

• connected components

• cutvertices

• biconnected components

Page 2: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 2

Connected Components• Connected Graph: any two vertices are connected

by a path.

• Connected Component: maximal connected subgraph of a graph.

connected not connected

Page 3: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

3

Equivalence Relations

• A relation on a set S is a set R of ordered pairs of elements of S defined by some property

• Example: S = {1,2,3,4} R = {(i,j) S X S such that i < j} = {(1,2),(1,3),(1,4),(2,3),

(2,4),{3,4)}

Page 4: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

4

Equivalence RelationsAn equivalence relation is a relation with the following properties:

(x,x) R, x S (reflexive)(x,y) R (y,x) R (symmetric)(x,y), (y,z) R (x,z) R (transitive)

The relation C can be defined as follows on the set of vertices of a graph: (u,v) C u and v are in the same connected component

C is an equivalence relation.

Page 5: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

5

DFS on a Disconnected Graph

• DFS(v) visits all the vertices and edges in the connected component of v.• To compute the connected components:

k = 0 // component counter

for each (vertex v)

if unvisited(v)

// add to component k the vertices

//reached by v

DFS(v, k++)

ab

d g

3

65

c

fe

Page 6: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

6

DFS on a Disconnected Graph

ab

d g

3

f5

c

e

ab

d g

3

65

c

fe

A DFS from vertex a gives us...

Page 7: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 7

Cutvertices

A Cutvertex (separation vertex) is one whose removal disconnects the graph.

In the above graph, cutvertices are: ORD, DEN

If the Chicago airport (ORD) is closed, then there is no way to get from Providence to cities on the west coast. Similarly for Denver.

MIA

SEA

SFO

ATL

PVD

LGA

STLLAXLAX

DFW

ORD

MSN

DEN

Page 8: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 8

BiconnectivityBiconnected graph: has no cutvertices

• New flights:LGA-ATL and DFW-LAX make the graph biconnected.

MIA

SEA

SFO

ATL

PVD

LGA

STLLAXLAX

DFW

ORD

MSN

DEN

Page 9: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 9

Properties of Biconnected Graphs

• There are two disjoint paths between any two vertices.

• There is a cycle through any two vertices.

By convention, two nodes connected by an edge form a biconnected graph, but this does not verify the above properties.

MIA

SEA

SFO

ATL

PVD

LGA

STLLAXLAX

DFW

MSN

DEN ORD

Page 10: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 10

Biconnected Components

• A biconnected component (block) is a maximal biconnected subgraph

MIA

SEA

SFO

ATL

PVD

LGA

STLLAXLAX

DFW

ORD

MSN

DEN

•Biconnected components are edge-disjoint but share cutvertices.

Page 11: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 11

Characterization of the Biconnected Components

We define an equivalence relation R on the edges of G: (e', e") R if there is a cycle containing both e' and e"

How do we know this is an equivalence relation? Proof (by pretty picture) of the transitive property:

e1 e2 e3

Page 12: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 12

Characterization of the Biconnected Components

• What does our equivalence relation R give us?

• Each equivalence class corresponds to:

– a biconnected component of G

– a connected component of a graph H whose vertices are the edges of G and whose edges are the pairs in relation R.

Page 13: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 13

DFS and Biconnected Components

• Graph H has O(m2) edges in the worst case.• Instead of computing the entire graph H, we use a smaller proxy

graph K.

c

b d

af

ei

h

g

g

h

if

ea

b

c d

•The connected components of K are the same as those of H!

Page 14: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 14

DFS and Biconnected Components

• Start with an empty graph K whose vertices are the edges of G.• Given a DFS on G, consider the (m -n +1) cycles of G induced by

the back edges.• For each such cycle C = (e0, e1, ... , ep) add edges (e0, e1) ... (e0, ep) to

K.

c

b d

af

ei

h

g

g

h

if

ea

b

c d

Page 15: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 15

A Linear Time Algorithm

We can further reduce the size of the proxy graph to O(m)– Process the back edges according to a preorder visit of their destination vertex in the DFS tree– Mark the discovery edges forming the cycles– Stop adding edges to the proxy graph after the first marked edge is encountered.– The resulting proxy graph is a forest!– This algorithm runs in O(n+m) time.

The size of K is O(mn) in the worst case.

Page 16: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 16

Example• Back edges labeled according to the preorder visit of their

destination vertex in the DFS tree

c

b

d

a

f

e1

g

h

e2 e3

e4

e6

e5

a g

e1 a b g h

e1

c

e2Processing e1 Processing e2

Page 17: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 17

Example (contd.)

c

b

d

a

f

g

h

e2 e3

e4

e6

e5

a b g h

e1

c

e2 e3

f

e4

d

e5

e6

DFS tree

final proxy graph (a tree since the graph is biconnected)

Page 18: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 18

Why Preorder?The order in which the back edges are processed is essential for the correctness of the algorithmUsing a different order ...

c

b

d

a

g

e1

e2

e3

g d b a

e2

e3

e1... yields a graph that provides incorrect information

Page 19: Connectivity1 Connectivity and Biconnectivity connected components cutvertices biconnected components

Connectivity 19

Try the Algorithm on this Graph!

MIA

SEA

SFO

ATL

PVD

LGA

STLLAXLAX

DFW

MSN

DEN

LAXSAN

SJU STT

ORD