CS 0/58,, Biconnectivity Let G = (N,E) be a connected A node a N is an articulation point if there are v and w different from a such that every path from 0 9 8 3 5 7 6 David Maier Biconnected Component Maximal subgraph that is still connected after Express in terms of edges 0 9 8 3 5 5 7 3 6 Articulation point must lie in two components David Maier
CS 0/58,, DFS and Articulation Points Tree, back edges in DFS give clue to articulation points If a is an articulation point that splits v and w, then 3 0 5 6 8 7 9 David Maier 3 DFS and Articulation Points Lemma: G = (N,E) is S = (N,T) is Node a is an articulation i point if and only if. a is the root of S and or. a is not the root and a has some child c in S where there is no David Maier
CS 0/58,, Low Numbers For graph G = (N,E), let T = B = For simplicity, assume DFNum[v] = How high (lowest DFNum) can we hop from a node on a back edge? LOW[v] = min({v} {w there is {x,w} in B where David Maier 5 Calculating Low If {x,w} in B and w < v then Also, v is an articulation point if for some child c of v, LOW[c] Calculate LOW during DFS LOW[v] is minimum of.. 3. David Maier 6 3
CS 0/58,, Biconnected Components Algorithm Count Parent[v] BI(v) mark v DFNum[v] Count, increment Count Low[v] DFNum[v] David Maier 7 Algorithm Cont. for each edge {v,w} do if w not marked then if LOW[w] DFNum[v] and v not root then LOW[v] else if PARENT[v] w then LOW[v] Need a check at end if root is an articulation point. David Maier 8
CS 0/58,, 0 9 8 Example 3 5 7 6 David Maier 9 Minimum Cost Spanning Tree G = (N, E) Cost function c gives edge weights A spanning tree is a graph S = ( ) where E E and S is a 3 3 5 6 7 3 6 David Maier 0 5
CS 0/58,, Cost of a spanning tree S = (N,E ) is e E Cost of a Spanning Tree Want minimum cost Lemma: Let S = (N,E ) be a spanning tree for G = (N,E). Then a. for v, v in N b. adding an edge from E-E to S David Maier Spanning Forest A set of trees {(N,E ), (N,E ),..., (N k,e k )} Where N = E i E E j 3 5 3 6 7 3 6 David Maier 6
CS 0/58,, Expanding a Spanning Forest Lemma: Suppose we have a spanning forest of k > trees. Let E = Let e = {v,w} be such that v N, w N. Then there is a spanning tree for G that includes E and has minimal cost among trees that include E. What kind of algorithm is this leading us towards? David Maier 3 Proof of Lemma Suppose not. Let S = (N,E ), E E, have lower cost than any spanning tree Adding e to S causes v w N v w David Maier 7
CS 0/58,, Proof of Lemma S must have an edge e = {v,w } with We know c(e) Let S = S S has no cycles c(e ) S is still a tree David Maier 5 Greedy Strategy Take least cost edge e in E. By last lemma, [Consider an initial spanning forest {({ }, ), ({ }, ),..., ({ }, )} ] David Maier 6 8
CS 0/58,, Iterative Step Let {(N,E ),(N,E ),...,(N k,e k )} be a spanning forest that is Add the lowest cost edge that By the last lemma, the result is David Maier 7 Kruskal s Algorithm KRUSKAL(G(N,E)) S NS {{v },{v },...,{v n }} Q while NS > do {v,w} if Find(v) Find(w) then S S Union( ) David Maier 8 9
CS 0/58,, Example Q c NS {,5} {} {} {3} {} {5} {6} {3,} {,} 3 {,5} 3 {,3} {,6} {,3} 6 {5,6} 7 David Maier 9 Complexity Priority Queue: sort, make a list Union/Find # Union s = # Find s = Can do a little better keep a heap of edges by cost David Maier 0 0
CS 0/58,, Path Problems Directed graphs with labels on edges a b 3 c e d 5 f David Maier Shortest Path Labels could be non-negative integers Use for 3 3 3 5 6 David Maier
CS 0/58,, Connectivity Labels could be Boolean values Use for 3 0 5 0 David Maier 3 Finite Automata Labels could be symbols from an alphabet (as in a finite automaton). Use for a b 3 b a b 5 a David Maier
CS 0/58,, Path Algorithms Can produce generic algorithms, just need definitions for Can take advantage of identities Two kinds of algorithms.. Can do. with David Maier 5 Dijkstra s Algorithm Single-source, shortest path in a digraph v 0 v v 5 v 3 v 9 7 3 v 6 v 7 v 8 v5 S D array of distances David Maier 6 3
CS 0/58,, General Step Add node not in S with minimum D value to S. Update distances to nodes in N-S Is S still correct? S v 0 w suppose not shortest David Maier 7 Full Algorithm G = (N,E) lab(v,w) - label represent with matrix S {v 0 } D[v 0 ] 0 D[v] lab(v 0,v) for rest while S N do choose w S for all v in N-S do D[v] David Maier 8
CS 0/58,, Example 3 3 5 6 S D[] D[] D[3] D[] D[5] {} 0 David Maier 9 Warshall s Algorithm Transitive Closure 3 5 Basic op k v w Consider each k only once v k w David Maier 30 5
CS 0/58,, Algorithm for k = to n do for v = to n do if a[v,k] then for w = to n do if a[k,w] then David Maier 3 Example 3 5 0 0 0 0 0 3 0 0 0 0 0 0 0 5 0 0 David Maier 3 6
CS 0/58,, Floyd s Algorithm All-pairs shortest path v k w for k = to n do for v = to n do if d[v,k] then for w = to n do d[v,w] David Maier 33 Example 3 3 3 d[i,j] 0 0 0 3 0 3 0 David Maier 3 7
CS 0/58,, Example 3 d[i,j] 0 0 0 3 0 3 0 3 d[i,j] 3 David Maier 35 Example 3 3 d[i,j] 0 0 3 0 3 3 6 0 3 d[i,j] 0 3 0 3 3 0 3 3 5 0 David Maier 36 8
CS 0/58,, Example 3 3 d[i,j] 0 3 0 3 3 0 3 3 5 0 3 d[i,j] 3 3 David Maier 37 9