19
Biconnected Components CS 312

Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Embed Size (px)

Citation preview

Page 1: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Biconnected Components

CS 312

Page 2: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Objectives

• Formulate problems as problems on graphs• Implement iterative DFS• Describe what a biconnected component is• Be ready to start project 2

Page 3: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Problems on Graphs

• What to store in each node of the graph?• What does it mean for two nodes to be

connected in the graph? • What property do I want to analyze about the

graph? – Then select or adapt an algorithm.

Page 4: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Generic graph explorationExplore (G, v) Input: G = (V,E) and v in V Output: visited(u) is true u for all u reachable

from v. visited(v) = true previsit(v) for each edge (v,u) E if not visited(u) then explore (u) postvisit (v)

Page 5: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Iterative DFS versionExploreIterDFS (G, v) Input: G = (V,E) and v in V Output: visited(u) is true u for all u reachable

from v. stack.push(v) if (stack.notEmpty()) v = stack.top visited(v) = true previsit(v) for the next edge (v,u) E if not visited(u) then stack.push(u) if all edges from v have been traversed then stack.pop(v) postvisit (v)

Page 6: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Iterative DFS versionExploreIterDFS (G, v) Input: G = (V,E) and v in V Output: visited(u) is true u for all u reachable

from v. stack.push(v) if (stack.notEmpty()) v = stack.top visited(v) = true previsit(v) for the next edge (v,u) E if not visited(u) then stack.push(u) if all edges from v have been traversed then stack.pop(v) postvisit (v)

Page 7: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Definitions

• Biconnected component– The largest set of edges such that… – There is a set of EDGES for which there is a simple

cycle between every edge– Or it is a single edge

• Bridge– Bicconnected component of size 1

• Separating vertex– Vertex which can be deleted to partition the graph.

Page 8: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Example

a

b

cd

e

fg

Page 9: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Example

a

b

cd

e

fg

Page 10: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

DFS Tree

Page 11: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

“Low” numbering

• “pre” ordering• “low” numbering

Page 12: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Separating Vertices

How does that translate into a test on low and pre?

Page 13: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

The Idea for the Algorithm

• If you can find low and pre, you can identify separating vertices. – You can use DFS to find low and pre.– Pre is easy.

• If you can find separating vertices, then you can use a second DFS to find biconnected components. – Keep in mind that the biconnected components

are edges not vertices.

Page 14: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Example

a

b

cd

e

fg

a

b

g

c

d

h

e

f

abbggccddg pop

h

Page 15: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Example

a

b

cd

e

fg

a,1

b,2

g,3

c,4

d,5

h,6

e,7

f,8

h

uv(v,w)wpre

upreulow

of descendant afor backedge a is where)(

)(min)(

pre numbering.

Page 16: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Example

a

b

cd

e

fg

a,1,1

b,2,1

g,3,3

c,4,3

d,5,3

h,6,6

e,7,3

f,8,3

h

uv(v,w)wpre

upreulow

of descendant afor backedge a is where)(

)(min)(

low numbering.

u is a sep. vertex iff there is a child v of u s.t.pre(u) “< or =“ low(v)

Page 17: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Example

a

b

cd

e

fg

a,1,1

b,2,1

g,3,3

c,4,3

d,5,5

h,6,6

e,7,3

f,8,8

h

uv(v,w)wpre

upreulow

of descendant afor backedge a is where)(

)(min)(

Computing low. Always initialize u.low = u.preWhen follow edge (u,v) and v is visited (and v != the DFS parent of u), u.low = min (u.low, v.pre)When pop u off DFS stack, pass low to parent. If u’s low is lower than it’s parent, then update parent.

h,6,6d,5,5c,4,4g,3,3b,2,2a,1,1

(vertex, pre, lowest low so far)

Page 18: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Example

a

b

cd

e

fg

a,1,1

b,2,1

g,3,3

c,4,3

d,5,5

h,6,6

e,7,3

f,8,8

h

uv(v,w)wpre

upreulow

of descendant afor backedge a is where)(

)(min)(

Computing low. Always initialize u.low = u.preWhen follow edge (u,v) and v is visited, u.low = min (u.low, v.pre)When pop u off DFS stack, pass low to parent. If u’s low is lower than it’s parent, then update parent.

d,5,5h,6,6d,5,5c,4,4g,3,3b,2,2a,1,1

(vertex, pre, lowest low so far)

d is visitedbut, d is h’s dfs parent

Do nothing.

Page 19: Biconnected Components CS 312. Objectives Formulate problems as problems on graphs Implement iterative DFS Describe what a biconnected component is Be

Example

a

b

cd

e

fg

a,1,1

b,2,1

g,3,3

c,4,3

d,5,5

h,6,6

e,7,3

f,8,8

h

uv(v,w)wpre

upreulow

of descendant afor backedge a is where)(

)(min)(

Computing components2nd DFSuse a stack of edges. push a mark onto the edge stack with the child of a SVwhen pop the child of an SV (in the node stack) pop back to the mark.

d,5,5h,6,6d,5,5c,4,4g,3,3b,2,2a,1,1

(vertex, pre, lowest low so far)

d is visitedbut, d is h’s dfs parent

Do nothing.