1 / 17

WEEK 13 Graphs V Depth-First Search, Depth-First Spanning Tree, Biconnectivity

WEEK 13 Graphs V Depth-First Search, Depth-First Spanning Tree, Biconnectivity. CE222 – Data Structures & Algorithms II Chapter 9.6.1, 9.6.2 (based on the book by M. A. Weiss, Data Structures and Algorithm Analysis in C++, 3rd edition, 2006). Depth First Search.

lot
Download Presentation

WEEK 13 Graphs V Depth-First Search, Depth-First Spanning Tree, Biconnectivity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WEEK 13Graphs VDepth-First Search, Depth-First Spanning Tree, Biconnectivity CE222 – Data Structures & Algorithms II Chapter 9.6.1, 9.6.2 (based on the book by M. A. Weiss, Data Structures and Algorithm Analysis in C++, 3rd edition, 2006)

  2. Depth First Search • Depth-first search is a generalization of preorder traversal. • Starting at some vertex, v, we process v and then recursively traverse all vertices adjacent to v. • If this process is performed on a tree, then all tree vertices are systematically visited in a total of O(|E|) time • Preorder traversal : • Visit Root • Visit Left Subtree • Visit Right Subtree CE 222-Data Structures & Algorithms II, Izmir University of Economics

  3. Depth First Search • If we perform this process on an arbitrary graph, we need to be careful to avoid cycles. • To do this, when we visit a vertex v, we mark it visited, since now we have been there, and recursively call depth-first search on all adjacent vertices that are not already marked. CE 222-Data Structures & Algorithms II, Izmir University of Economics

  4. Depth First Search Algorithm void dfs( vertex v ) { visited[v] = TRUE; for each w adjacent to v if( !visited[w] ) dfs( w ); } Because this strategy guarantees that each edge is encountered only once, the total time to perform the traversal is O(|E| + |V|), as long as adjacency lists are used. CE 222-Data Structures & Algorithms II, Izmir University of Economics

  5. Depth First Spanning Tree The root of the tree is A, the first vertex visited. Each edge (v, w) in the graph is present in the tree: • If, when we process (v, w), we find that w is unmarked, or if, when we process (w, v), we find that v is unmarked, we indicate this with a tree edge. • If, when we process (v, w), we find that w is already marked, and when processing (w, v), we find that v is already marked, we draw a dashed line, which we will call a back edge, to indicate that this "edge" is not really part of the tree. CE 222-Data Structures & Algorithms II, Izmir University of Economics

  6. Undirected graph and Depth First Spanning Tree • A preorder numbering of the tree (using only tree edges) will tell us the order in which vertices are marked. Preorder traversal, in this case, is: • Visit Root, Visit Children. • Ifthetree is not connectedthenprocessingallnodesrequiresseveralcallstodfs depthfirstspanningforest CE 222-Data Structures & Algorithms II, Izmir University of Economics

  7. Biconnectivity • A connected undirected graph is biconnected if there are no vertices whose removal disconnects the rest of the graph. Example : If the nodes are computers and the edges are links, then if any computer goes down, network mail is unaffected, except, of course, at the down computer. CE 222-Data Structures & Algorithms II, Izmir University of Economics

  8. Biconnectivity • If a graph is not biconnected, the vertices whose removal would disconnect the graph are known as articulation points. These nodes are critical in many applications. CE 222-Data Structures & Algorithms II, Izmir University of Economics

  9. Biconnectivity • The graph below is not biconnected:C and D are articulation points. The removal of C would disconnect G, and the removal of D would disconnect E and F, from the rest of the graph CE 222-Data Structures & Algorithms II, Izmir University of Economics

  10. Biconnectivity • Depth-first search provides a linear-time algorithm to find all articulation points in a connected graph. • Starting at any vertex, perform a depth-first search and number the nodes as they are visited: num(v). • For every vertex v in the depth-first spanning tree, compute the lowest-numbered vertex called low(v), that is reachable from v by taking zero or more tree edges and then possibly one back edge (in that order). CE 222-Data Structures & Algorithms II, Izmir University of Economics

  11. Biconnectivity • The depth-first spanning tree shows the preorder number first, and then the lowest-numbered vertex reachable • (For each node num/low is given in the tree) CE 222-Data Structures & Algorithms II, Izmir University of Economics

  12. Biconnectivity • The lowest-numbered vertex , low(v), can be efficiently computed by performing a postorder traversal of the depth-first spanning tree, and it is the minimum of • num(v) • the lowest num(w) among all back edges (v, w) • the lowest low(w) among all tree edges (v, w) CE 222-Data Structures & Algorithms II, Izmir University of Economics

  13. Biconnectivity: How to decide Articulation Points • The root is an articulation point if and only if it has more than one child (because if it has two children, removing the root disconnects nodes in different subtrees, and if it has only one child, removing the root merely disconnects the root.) • Any other vertex v is an articulation point if and only if v has some child w such that low(w)≥ num(v). Example: Vertex D is an articulation point  low(E)= 4 ≥ num(D)=4 Vertex C is an articulation point  low(G)= 7 ≥ num(C)=3 CE 222-Data Structures & Algorithms II, Izmir University of Economics

  14. 1) Computing num(v) • A preorder traversal to compute num(v). CE 222-Data Structures & Algorithms II, Izmir University of Economics

  15. 2) Computing low(v) • A postorder traversal to compute low(v). • To save a third traversal for finding articulation points, it is also incorporated into the second pass. CE 222-Data Structures & Algorithms II, Izmir University of Economics

  16. Articulation point algorithm(All phases combined) Do not forget to study Figures 9.65, 9.66, and 9.67! (assigning num(v) and low(v) and finding articulation points) CE 222-Data Structures & Algorithms II, Izmir University of Economics

  17. Homework Assignments • 9.21, 9.22, 9.23a, 9.24, 9.25 • You are requested to study and solve the exercises. Note that these are for you to practice only. You are not to deliver the results to me. Izmir University of Economics

More Related