TO 1 Finding two vertex connected components in linear time Guy Kortsarz
TO 2 ackward 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. ackward 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. ut we backtracked, which is a contradiction. e prove a claim: laim: Every graph G(V,E) has a tree T(V,E ) so that every edge in E E is a backward edge.
TO 3 n example of a DFS run k=1 D E F G k=13. K=12 Y X k=2 D k=3 k=4 H Z E k=5 X J K F k=6 Y G k=7 k 8 H k=9 J k=11 K k=10 Figure 1: n example of a DFS ran
TO 4 The order of traversal of edges First, then (ignored), then D, then D, (backward edge. be for short) D, (be),, E, E (be) E (be), E, (ignored) EF, FE (ignored), FG, GH HE (be), HF (be), HG (ignored) HJ, JK, KH (be) KJ (ignored). acktrack to H, HZ, ZH (ignored) backtrack to. X X (ignored) XY, Y (be) YX (ignored) backtrack to. Finish.
TO 5 nother example E D F Y w P x S Z Q R Figure 2: Run DFS. Say the order we go over edges
TO 6 The tree E k=1 D F Y w k=2 k=3 P x S Z X k=12 k=8 P D k=4 k=5 F Q R Y k=14 k=13 R Q k=10 k=9 E k=6 k=7 Z k=15 S k=11 Figure 3: DFS run
TO 7 Order of the edges, (ignored),, (be) (ignored) D, D (be), D (be) D (ignored) DF, FE E, F (be) acktrack to D. DP, PQ (ignored), QP (ignored) QR, RS, SR (ignored) SQ (be), backtrack to D. DX, XD (ignored) XY, YE, Y (ignored), Z, Z (ignored) ZY (be) acktrack to. Finish.
TO 8 Long paths e show using DFS that any graph has a path of length at least m/n. If m = n 2 /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. e now upper bound the number of edges as a function of the height. ecause 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
TO 9 Separating vertices These are vertices whose removal disconnects the graph. E k=1 D F Y w k=2 k=3 P x S Z X k=12 k=8 P D k=4 k=5 F Q R Y k=14 k=13 R Q k=10 k=9 E k=6 k=7 Z k=15 S k=11 Figure 4: The Run of DFS Separating vertices here: {D,X,Y,P,Q}.
TO 10 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 e 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 SF from any s G v. If one of the distances is infinite v is a separating vertex. ut 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)
TO 11 n algorithm to find all separating vertices Definition: 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 T v 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.
TO 12 separating vertex U, UX, XM M M M M X X U E Y UY YE E EY MX FZ FU E XU U UD UY YU YE UZ ZU ZF 1 U U E X D Y Z 2 U X M M U X X 3 Y 9 Z 11 M M X M 4 7 8 10 D E F 12 U X 5 6 D X U Y U E Z U F F Z U Figure 5: X is not a separating vertex. ecause it does not separate his three children from their grandparent. M can go down to 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. has a backward edge above X, and so does D. However U is a separating vertex because Z can not go down T z and jump above U
TO 13 Low number of a vertex How close to the root can a vertex get? hat 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. lso 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.
TO 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 T Q with Q a child of P and use one backward edge inside T Q. The least number it can get bounds L(P) from above
TO 15 Example U, UX, XM M M M M X X U E Y UY YE E EY MX FZ FU E XU U UD UY YU YE UZ ZU ZF 1 U U E X D Y Z 2 U X M M U X X 3 Y 9 Z 11 M M X M 4 7 8 10 D E F 12 U X 5 6 D X U Y U E Z U F F Z U Figure 6: L() = 1 by rule 1. L(U) = 1 by going down to 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() = 2 by rule 2. L(D) = 2 by rule 2. L(E) = 1 by rule 2. L(F) = 2 by rule 2. L() = 1 by rule 2. L() = 3 by rule 2.
TO 16 theorem 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 T v 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.
TO 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). laim: 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.
TO 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
TO 19 Thinking on it as a recursive algorithm Let U ve a vertex and V 1,V 2,...,V k children of U. learly L(U) min{l(v 1 ),L(V 2 ),...,L(V k )} if z is a child of u then L(u) L(z). Think recursively. hen 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).
TO 20 Finding separating vertices E k=1 D F Y w k=2 k=3 P x S Z X k=12 k=8 P D k=4 k=5 F Q R Y k=14 k=13 R Q k=10 k=9 E k=6 k=7 Z k=15 S k=11 Figure 7: Finding separating vertices
TO 21 The run of the algorithm L() 1, L() 2, L() 3, L() 1, L(D) 4 L(D) 1 L(F) 5. L(E) 6, L(E) 4 L() 7 L() 5, acktrack L() < 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 acktrack L(R) 9. L(S) < k(r). acktrack. L(R) k(p), P is separating. L(P) > k(d),d is separator. L(X) 12. L(Y) 13, L() 14, L(Z) 15, L(Z) 13. L() 15 L(Z) < k(y). acktrack. L() 13. L() k(y), Y is separating. L(Y) k(x), X is sep. L(D) < k(), L() < k(). not separating.
TO 22 2 vertex connected components 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. nother 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. 2 vertex connected component is also called a (bio connected component) if 1. The subgraph is two vertex connected and 2. The subgraph is not contained in a larger
TO 23 Examples In trees the are every edge (note that a vertex alone is never a ). Figure 8: The of a graph, example
TO 24 The theory of the laim: The size of the intersection over vertices of two is at most one. Namely the following is not possible. Figure 9: Two can not have intersection of size 2
TO 25 proof e show that if we remove, is still connected. similar proof holds for and an easier proof follows for removing any vertex that is not or. onsider alone, disregarding. This is a and in partial it it two vertex connected. Thus removing leaves a connecting graph. In the same way disregarding, removing from leaves a connected graph. Let 1 =, 2 =. e know that 1. 1 and 2 are connected. 2. They share a vertex and so 1 2 is connected. 3. ut this means that is a that contains both and. 4. This is a contradiction
TO 26 The unique intersecting vertex onsider the graph induced by. say that they intersect at a. See the following figure Figure 10: Two that intersect on a
TO 27 Proof oth X, X for X a can reach a as, are. If we remove a by the assumption toward a contradiction the graph remain connected. Thus is a two vertex connected subgraph, which is a contradiction
TO 28 a cycle of cant exist e define a path 1, 2, 3... on. The path is legal in i, i+1 intersect on separating vertex. Here is an example of a path of. 2 1 3 Figure 11: n example
TO 29 cycle can not exists G F E D Figure 12: This structure cant exist
TO 30 hy not? onsider the following example. 1 2 8 J 3 7 H F D 4 6 5 Figure 13: This cant be
TO 31 Proof Say that is removed, separating 1 and 2. However by the definition of a, every vertex in 1 can reach J, then H, then F, then D then, Then which means that 1 can reach any vertex of 2. Thus the entire cycle in vertex 2-connected, contradiction.
TO 32 leaf component Let P be a longest path in a graphs. Let, be the two at the start and end of the path. The, can not intersect a that is outside as this will imply that the path is not longest. The can not intersect anyone in the middle of the path as otherwise we get a cycle of. Thus both, intersect one. y the claims above it contains one separating vertex. alled a leaf component. Theorem: There are always at least 2 with a single separating vertices. Remark: Most have much more than be separating vertex.
TO 33 high level of a run 6 E E 5 D D 4 3 2 1 Figure 14: Moving via non leaf until we get to a leaf
TO 34 Intuition for finding onsider an edge eating monster. He eats an edge and also pushes it to a STK. It starts at some 1. Unfortunately, it may leave 1 to 2 2 before it eats (puts on the stack) all the edges of 1. Now, since 1 has more than one separating vertex the monster can get out of 1 before it eats all the edges of 1. It goes out by another separating vertex. The same hold true for 2, 3, 4, 5.
TO 35 ontinued hat we have on the stack is a completely mixed collection of edges. How do we find a? ut it must eventually reach a leaf components, 6. 6 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. t this moment all the edges of all the leaf 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 and means that U is a separating vertex. e will discover at that stage that L(F) k(e) thus we found a separating vertex. nd since we backtracked, Finding a separating vertex implies we also found a leaf component.
TO 36 hat 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 6. e know that we backtrack, so the 6 must be a leaf (if there are two separating vertices we will leave the when we get to the second separating vertex). It may not have been a leaf at start but its a leaf now. This does not mix edges of 6 with the edges of any because we backtracked.
TO 37 ontinued It very simple to find the. Each time you find a separating vertex it means that you did backtracking, and so the 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 because we used a stack. s soon as we find the X is a separating vertex for Y, remove all the edges until XY including. Declare that the next. e now go over the algorithm and later see an example. Think why it is good that the root is always considered a separating vertex
TO 38 n example of a run of the algorithm E k=1 D F Y w k=2 k=3 P x S Z X k=12 k=8 P D k=4 k=5 F Q R Y k=14 k=13 R Q k=10 k=9 E k=6 k=7 Z k=15 S k=11 Figure 15: The Run of DFS
TO 39 The run {(,),(,),(,),(,D),(D,),(D,), (D,F),(F,E),(E,D),(E,),(,F)} acktrack, D separating F, Take all edges till (D,F) {(D,F),(F,E),(E,D))(E,),(,F)} First. {(),(,),(,),(,D),(D,),(D,), (D,P)(P,Q),(Q,R),(R,S)),(S,Q)}. Q separate R. ll edges till (Q,R). {(Q,R),(R,S),(S,Q)} are the next.
TO 40 ontinued {(),(,),(,),(,D),(D,),(D,), (D,X),(X,Y)(Y,),(.Z),(Z,Y)}. Y separates. Next {(Y,),(,Z),(Z,Y)} {(,),(,),(,),(,D),(D,), (D,X)(X,Y)} X separates Y, thus {(X.Y)} the next. D separates X and so {(D,X)}, next. ack to, {(),(,),(,),(,D),(D,),(D,)}. ll the edges, last. ecause considered a separating vertex.