43
TOC 1 Finding two vertex connected components in linear time Guy Kortsarz

Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 1

Finding two vertexconnected components in

linear time

Guy Kortsarz

Page 2: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 2

Backward edges

Please read the DFS algorithm (its in the

lecture notes).

The DFS gives a tree. The edges on the tree

are called tree edges. The rest are called

backward edges.

Backward edges must go from a vertex to its

ancestor.

Indeed what if there is a side edge a b and say

that we got to a before b,

Since b is unvisited (it came after a) we should

have recursed with b. But we backtracked,

which is a contradiction.

We prove a claim:

Claim: Every graph G(V,E) has a tree

T (V,E′) so that every edge in E − E′ is a

backward edge.

Page 3: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 3

An example of a DFS run

A

B

C

D

E

F

G

H

JK

X

Y

A

B

k=1

k=2

k=3

k=4

D

C

E

F

G

H

Z

J

K

k=5

k=6

k=7

k−8

k=9

k=10k=11

X

Y

K=12

k=13.

Figure 1: An example of a DFS ran

Page 4: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 4

The order of traversal of edges

First AB, then BA (ignored), then BD, then

DA, (backward edge. be for short) DC, CA

(be), CB, CE, AE (be) BE (be), EC,

(ignored) EF , FE (ignored), FG, GH HE

(be), HF (be), HG (ignored) HJ , JK, KH

(be) KJ (ignored). Backtrack to H, HZ, ZH

(ignored) backtrack to A. AX XA (ignored)

XY , Y A (be) Y X (ignored) backtrack to A.

Finish.

Page 5: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 5

Another example

A

B

C

D

E

F

W

P

Q

R

S

x

Z

Yw

Figure 2: Run DFS. Say the order we go over

edges

Page 6: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 6

The tree

A

B

C

D

E

F

W

P

Q

R

S

x

Z

Yw

A

B

C

D

k=1

k=2

k=3

k=4

F

E

k=5

k=6

P

Q

R

S

W

k=7

k=8

k=9

k=10

k=11

X

Y

Z

k=12

k=13

k=14

k=15

G

Figure 3: A DFS run

Page 7: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 7

Order of the edges

AB, BA (ignored), BC, CA (be) CB (ignored)

CD, DA (be), DB (be) DC (ignored) DF , FE

EW , WF (be) Backtrack to D. DP , PQ

(ignored), QP (ignored) QR, RS, SR (ignored)

SQ (be), backtrack to D. DX, XD (ignored)

XY , Y E, WY (ignored), WZ, ZW (ignored)

ZY (be) Backtrack to A. Finish.

Page 8: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 8

Long paths

We show using DFS that any graph has a path

of length at least m/n.

If m = n2/20 for example this gives n/20

length path. Very long

To find such a path just take any DFS tree and

take the height.

We now upper bound the number of edges as a

function of the height.

Because all edges are backward edges n · h ≥ m.

This only happens with leaves of level h that

have all edges to their ancestors.

This implies that h ≥ m/n

Page 9: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 9

Separating vertices

These are vertices whose removal disconnects

the graph.

A

B

C

D

E

F

W

P

Q

R

S

x

Z

Yw

A

B

C

D

k=1

k=2

k=3

k=4

F

E

k=5

k=6

P

Q

R

S

W

k=7

k=8

k=9

k=10

k=11

X

Y

Z

k=12

k=13

k=14

k=15

G

Figure 4: The Run of DFS

Separating vertices here: {D,X, Y, P,Q}.

Page 10: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 10

A trivial and slow algorithm to

find all separating vertices

Note we assume from now on that the

graph is connected as otherwise it makes

no sense

We can go over all vertices and for each vertex

remove it and all its edges. This means that

the linked lists change.

If we are now at vertex v look at G− v. Do a

BSF from any s ∈ G− v. If one of the

distances is infinite v is a separating vertex.

But this taken O(n(n+m)). Thus is not linear

in n and m. Our next task is to give an

algorithm that finds all separating vertices in

O(m+ n)

Page 11: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 11

An algorithm to find all separating

vertices

Definition: A separating vertex in a connected

graph is a vertex whose deletion together with

its edges, makes the graph disconnected.

It is quite convenient that a vertex has only up

edges. Let Tv be the subtree rooted at v. Let

p(v) be the parent of v. Not having side edges

means that a vertex v can go to or above his

parent only by going down to a descendant and

using an up edge that goes above his parent.

This is illustrated in the next slide by a figure.

Page 12: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 12

A separating vertex

W

XY Z

AB

CD E F

U

M

1

2

3

4

5

6

78

9

10

11

12

W

U

X

M

A

B

C

D

Y

E

Z

F

X W D Y Z

W Y

U A E

M C

A B

W M

M

U

X U

U E

U F

Z U

X

C

X

X

WU, UX, XM MA AW AM MB BM BX XC CU

UY YE EW EY MX

BU

XU UC UD UY YU YE UZ ZU ZF

FZ FU WA WE

Figure 5: X is not a separating vertex. Because

it does not separate his three children from their

grandparent. M can go down to A and then to

the root (thus if X is taken out M can reach

its grandparent of X by going to the root and

going down to U . C has a backward edge above

X, and so does D. However U is a separating

vertex because Z can not go down Tz and jump

above U

Page 13: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 13

Low number of a vertex

How close to the root can a vertex get?

What is the minimum k(v) that a vertex u can

reach using at most one back edge?

It may be that back edges do not help and the

lowest k value that u can get to is k(u).

It may be that u has back edges. The back

edge that goes highest is a candidate for the

low number.

Also lets think of vertices on descendants of v

have backward edges. Trampolines as I call it.

Go down to the best trampoline and jump

once.

Page 14: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 14

The definition of L(u)

L(u) is the the vertex with least k value that a

vertex can reach without using its parent.

There are 3 ways to get lower L(P ).

1. k(u) (meaning stay put). It is always true

that L(P ) ≤ k(P )

2. If a vertex has backward edges go out of u

we can choose the L(u) to be the minimum

k value.

3. U can go down to some TQ with Q a child

of P and use one backward edge inside TQ.

The least number it can get bounds L(P ) from

above

Page 15: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 15

Example

W

XY Z

AB

CD E F

U

M

1

2

3

4

5

6

78

9

10

11

12

W

U

X

M

A

B

C

D

Y

E

Z

F

X W D Y Z

W Y

U A E

M C

A B

W M

M

U

X U

U E

U F

Z U

X

C

X

X

WU, UX, XM MA AW AM MB BM BX XC CU

UY YE EW EY MX

BU

XU UC UD UY YU YE UZ ZU ZF

FZ FU WA WE

Figure 6: L(W ) = 1 by rule 1. L(U) = 1 by

going down to A and jumping (rule 3). L(X) =

1 by rule 3. L(Y ) = 1 by rule 3. L(Z) = 2

by rule 3. L(M) = 1 by rule 3. L(C) = 2 by

rule 2. L(D) = 2 by rule 2. L(E) = 1 by rule

2. L(F ) = 2 by rule 2. L(A) = 1 by rule 2.

L(B) = 3 by rule 2.

Page 16: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 16

A theorem

A vertex u is a separator vertex if and only if

for every child v, low(v) < k(v).

Namely if every child can reach the

grandparent.

Note that the grand parent can reach the root

even if par(u) is remove and so can all other

vertices.

For example a vertex in Tv a tree rooted by a

child v of u has a path to par(par(u)) and so to

the root, if par(u) is deleted.

Page 17: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 17

The inequality that implies a

separating vertex

Let v be the child of u with u not the root.

If L(v) ≥ k(u) it means that v can not jump

over his parent u.

Thus the removal of u disconnects v from

par(u).

Claim: a vertex u is separating if and only if

for some child v of u, L(v) ≥ k(u).

If this holds than after u is remove v and p(u)

have no path in G− u.

Page 18: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 18

The root will always be considered

a separating vertex

However the root is a separating vertex, if and

only if it has at least two children.

This is because up edges do not exist.

If it has one child, clearly the removal of the

root leaves a single connected component.

If it has two children or more then as there are

no side edges, the two children will become

disconnected.

For the purpose of finding 2 vertex connected

components (later) its good to treat the root as

a separating vertex

Page 19: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 19

Thinking on it as a recursive

algorithm

Let U ve a vertex and V1, V2, . . . , Vk children of

U .

Clearly L(U) ≤ min{L(V1), L(V2), . . . , L(Vk)} if

z is a child of u then L(u) ≤ L(z).

Think recursively. When we get back to a child

of Z, of U we know the low number of the child

L(Z). Then we can set

L(U)← min{L(U), L(Z)}.

Second, when we discover a backward edge say

UZ, then L(U)← min{L(U), k(Z)}.

Read the algorithm for finding separating

vertices (in the slide notes).

Page 20: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 20

Finding separating vertices

A

B

C

D

E

F

W

P

Q

R

S

x

Z

Yw

A

B

C

D

k=1

k=2

k=3

k=4

F

E

k=5

k=6

P

Q

R

S

W

k=7

k=8

k=9

k=10

k=11

X

Y

Z

k=12

k=13

k=14

k=15

G

Figure 7: Finding separating vertices

Page 21: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 21

The run of the algorithm

L(A)← 1, L(B)← 2, L(C)← 3, L(C)← 1,

L(D)← 4 L(D)← 1 L(F )← 5. L(E)← 6,

L(E)← 4 L(W )← 7 L(W )← 5, Backtrack

L(W ) < k(E). L(E) < k(F ) L(F ) ≥ k(D). D

separator. L(P )← 8, L(Q)← 9, L(R)← 10,

L(S)← 11. L(S)← 9 Backtrack L(R)← 9.

L(S) < k(R). Backtrack. L(R) ≥ k(P ), P is

separating. L(P ) > k(D),D is separator.

L(X)← 12. L(Y )← 13, L(W )← 14,

L(Z)← 15, L(Z)← 13. L(W )← 15

L(Z) < k(Y ). Backtrack. L(W )← 13.

L(W ) ≥ k(Y ), Y is separating. L(Y ) ≥ k(X),

X is sep. L(D) < k(C), L(C) < k(B). A not

separating.

Page 22: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 22

2 vertex connected components

A graph is vertex two connected if for every

two vertices v, u in the graph there are at least

two paths between u and v. Another way to

say that a graph is two vertex connected is

saying that graph has no separating vertices.

If a graph is not two vertex connected a 2

connected component is a maximum size

subgraph that is two vertex connected.

A 2 vertex connected component is also called

a BCC (bio connected component) if

1. The subgraph is two vertex connected and

2. The subgraph is not contained in a larger

BCC

Page 23: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 23

Examples

In trees the BCC are every edge (note that a

vertex alone is never a BCC).

Figure 8: The BCC of a graph, example

Page 24: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 24

The theory of the BCC

Claim: The size of the intersection over vertices

of two BCC is at most one. Namely the

following is not possible.

A

B

C C’

Figure 9: Two BCC can not have intersection of

size 2

Page 25: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 25

A proof

We show that if we remove A, C ∪ C ′ is still

connected. A similar proof holds for B and an

easier proof follows for removing any vertex

that is not A or B.

Consider C alone, disregarding C ′. This is a

BCC and in partial it it two vertex connected.

Thus removing A leaves a connecting graph.

In the same way disregarding C, removing A

from C ′ leaves a connected graph.

Let C1 = C −A,C2 = C −B.

We know that

1. C1 and C2 are connected.

2. They share a vertex B and so C1 ∪ C2 is

connected.

3. But this means that C ∪ C ′ is a BCC that

contains both C and C ′.

4. This is a contradiction

Page 26: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 26

The unique intersecting vertex

Consider the graph induced by C ∪ C ′. say

that they intersect at a.

See the following figure

C C’

A

Figure 10: Two BCC that intersect on a

Page 27: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 27

Proof

Both C −X,C ′ −X for X 6= a can reach A as

C,C ′ are BCC.

If we remove a by the assumption toward a

contradiction the graph C ′ ∪ C remain

connected.

Thus C ∪ C ′ is a two vertex connected

subgraph, which is a contradiction

Page 28: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 28

A a cycle of BCC cant exist

We define a path C1, C2, C3 . . . on BCC. The

path is legal in Ci, Ci+1 intersect on separating

vertex.

Here is an example of a path of BCC.

CC1

C2

C3

Figure 11: An example

Page 29: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 29

A cycle can not exists

A B

C

DE

F

G

Figure 12: This structure cant exist

Page 30: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 30

Why not?

Consider the following example.

A

B

C

DF

H

J

C1

C2

C3

C4

C5C6

C7

C8

Figure 13: This cant be

Page 31: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 31

Proof

Say that A is removed, separating C1 and C2.

However by the definition of a BCC, every

vertex in C1 can reach J , then H, then F , then

D then C, Then B which means that C1 can

reach any vertex of C2. Thus the entire cycle in

vertex 2-connected, contradiction.

Page 32: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 32

A leaf component

Let P be a longest path in a BCC graphs.

Let A,B be the two BCC at the start and end

of the path.

The BCC A,B can not intersect a BCC C that

is outside as this will imply that the path is not

longest.

The BCC A can not intersect anyone in the

middle of the path as otherwise we get a cycle

of BCC.

Thus both A,B intersect one BCC.

By the claims above it contains one separating

vertex. Called a leaf component.

Theorem: There are always at least 2 BCC

with a single separating vertices.

Remark: Most BCC have much more than be

separating vertex.

Page 33: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 33

A high level of a run

A

A

BB

C

C

D

D

EE

C1C2

C3C4C5

C6

Figure 14: Moving via non leaf BCC until we

get to a leaf BCC

Page 34: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 34

Intuition for finding BCC

Consider an edge eating monster. He eats an

edge and also pushes it to a STACK.

It starts at some BCC C1. Unfortunately, it

may leave C1 to C22 before it eats (puts on the

stack) all the edges of C1.

Now, since C1 has more than one separating

vertex the monster can get out of C1 before it

eats all the edges of C1. It goes out by another

separating vertex.

The same hold true for C2, C3, C4, C5.

Page 35: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 35

Continued

What we have on the stack is a completely

mixed collection of edges. How do we find a

BCC?

But it must eventually reach a leaf

components, C6.

C6 has one separating vertex. Think of

separating vertices as out points. If you have

one end point, (one separating vertex) you will

eat all the edges before you backtrack.

At this moment all the edges of all the leaf

BCC are on the top of the stack.

The deep most edge in the Stack (hence the

one to go out first is U − V that enters the

BCC and means that U is a separating vertex.

We will discover at that stage that

L(F ) ≥ k(E) thus we found a separating

vertex. And since we backtracked, Finding a

separating vertex implies we also found a leaf

component.

Page 36: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 36

What do we know

Say that E separates F . So EF was the first

edge (and also first edge in the stack) among

the edges of BCC C6.

We know that we backtrack, so the BCC C6

must be a leaf BCC (if there are two separating

vertices we will leave the BCC when we get to

the second separating vertex).

It may not have been a leaf BCC at start but

its a leaf BCC now.

This does not mix edges of C6 with the edges

of any BCC because we backtracked.

Page 37: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 37

Continued

It very simple to find the BCC. Each time you

find a separating vertex it means that you did

backtracking, and so the BCC of this vertex is

a leaf component.

If you enter the component with XY XY will

be the first in the stack. edge in the BCC

because we used a stack.

As soon as we find the X is a separating vertex

for Y , remove all the edges until XY including.

Declare that the next BCC.

We now go over the algorithm and later see an

example.

Think why it is good that the root is always

considered a separating vertex

Page 38: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 38

An example of a run of the

algorithm

A

B

C

D

E

F

W

P

Q

R

S

x

Z

Yw

A

B

C

D

k=1

k=2

k=3

k=4

F

E

k=5

k=6

P

Q

R

S

W

k=7

k=8

k=9

k=10

k=11

X

Y

Z

k=12

k=13

k=14

k=15

G

Figure 15: The Run of Finding BCC

Page 39: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 39

The run

AB and then BA. Nothing happens.

BC, The stack < BC,AB >

CA The stack < CA,BC,AB >, CB nothing

happens.

CD. The stack < CD,CA,BC,AB > DF ,

The stack < DF,CD,CA,BC,AB >

FE The stack < FE,DF,CD,CA,BC,AB

EW The stack

< EW,FE,DF,CD,CA,BC,AB > Then

WF . The stack

< WF,EW,FE,DF,CD,CA,BC,AB >

Backtrack. E is not separating and F is not

separating. But adds ED to the stack. The

stack is

< ED,WF,EW,FE,DF,CD,CA,BC,AB >

D separates F . The first BCC is all the edges

till DF . {ED,WF,EW,FE,DF}

Page 40: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 40

Continued

DP The stack is < DP,CD,CA,BC,AB >

PQ. The stack is

< PQ,DP,CD,CA,BC,AB >

QR. The stack is

< QR,PQ,DP,CD,CA,BC,AB >

RS. The stack is:

< RS,QR,PQ,DP,CD,CA,BC,AB >

SP , added to the stack and then SR for which

nothing happens. The stack

< SP,RS,QR,PQ,DP,CD,CA,BC,AB >

SQ is added. The stack is <

SQ,SP,RS,QR,PQ,DP,CD,CA,BC,AB,CB >

Backtracks and R is not separating. Backtracks

Q is not separating

P is separation. Take out all edges until PQ:

{SQ, SP,RS.QR,PQ}. The stack

< DP,CD,CA,BC,AB >.

Page 41: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 41

Backtrack to D

D separates X

Take out all edges up to DP .

DP is the upper edges. Next BCC {DP}

Page 42: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 42

Going QX

The stack is < QX,CD,CA,BC,AB,CB >

XY < XY,DX,CD,CA,AB,CB >.

Y G. < Y G,XY,DX,CD,CA,AB,CB >.

ZG,ZY ,

< ZY,GZ, Y G,XY,DX,CD,CA,AB,CB >.

Backtrack. Q is not separating. Y is. Remove

all the edges until Y G. {ZY,GY, Y G} the next

BCC.

The stack is now XY,DX,CA,AB,CB >.

Page 43: Finding two vertex connected components in linear timeguyk/dfss.pdf · TOC 2 Backward edges Please read the DFS algorithm (its in the lecture notes). The DFS gives a tree. The edges

TOC 43

Backtracking to X

X separates Y . Remove all edges till XY . This

gives {XY } Add DA and then DB.

< DB,DA,CD,CA,BC,AB > A will be

declared (by mistake) a separating vertex.

{DB,DA,CD,CA,BC,AB}