1 / 21

Graph Connectivity

Graph Connectivity. This discussion concerns connected components of a graph. Previously, we discussed depth-first search (DFS) as a means of determining connected components. Here, we are concerned with whether there is more than one way to get from one vertex to another. K. J. J. L. L. M.

rigel-ellis
Télécharger la présentation

Graph Connectivity

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. Graph Connectivity This discussion concerns connected components of a graph. Previously, we discussed depth-first search (DFS) as a means of determining connected components. Here, we are concerned with whether there is more than one way to get from one vertex to another.

  2. K J J L L M M Connected Components We’ll look at a generalization of connectivity known as biconnectivity. A graph is said to be biconnected if and only if there are at least two different paths connecting each pair of vertices. So even if a vertex and all the edges touching it are removed, the graph is still connected. biconnected Not biconnected

  3. A H I G B C K J D E L M F Biconnectivity An articulation point in a connected graph is a vertex that, if deleted, would break the graph into two or more pieces. A graph with no articulation point is said to be biconnected.

  4. A H I G B C K J D E L M F Biconnectivity A graph that is not biconnected divides into biconnected components, sets of nodes mutually accessible via two distinct paths. This graph consists of the biconnected components {A,C,G,D,E,F}, {G,J,L,M}, {B}, {H}, {I}, and {K}.

  5. A A A G B C G B C G B C D D E E D E F F F A A A G G B C B C G B C D D D E E E F F F DFS revisited

  6. A A G G B B C C D D E E F F A A G B C G B C D E D E F F DFS revisited

  7. A A B F C G B C E D E D G F DFS results representation Actual graph Traversal path Solid lines indicate that the lower vertex was found by the algorithm to be on the edge list of the upper vertex, and had not been visited at the time, so that a recursive call was made. Dotted lines correspond to edges to vertices that had already been visited, and the edge was not “followed” with a recursive call.

  8. A H I G B C A K J D B E F L M F E G L D C J H M K I Determining Articulation points Determining articulation points is a simple extension of DFS. Here. Deleting E does not disconnect the graph because G and D both have dotted links that point above E, giving alternate paths from them to F (E’s parent in the tree). However deleting G does disconnect the graph, because there is no alternate path from L or H to E (G’s parent).

  9. A A H I G B C B F K J D E L M E F G L D C J H M K I Determining Articulation points A vertex x is not an articulation point if every child y has some node lower in the tree connected (via dotted links) to a node higher in the tree than x, thus providing an alternate connection from x to y. This does not quite work for the root of the DFS, since there are no nodes “higher in the tree”. The root is an articulation point if it has two or more children, since the only path connecting children of the root goes through the root.

  10. A A H I G B C B F K J D E L M E F G L D C J H M K I Determining Articulation pointsRoot Node Special Case The DFS number of the root will always be 1 and any descendant of the root will have a min reachable number >= 1. By our previous definition, this would always make the root of the DFS tree an articulation point. However, the root in fact is only an articulation point if it has 2 or more children in the DFS tree. The only way the root will have 2 or more children is if the DFS algorithm had to backtrack to the root and proceed again to another of the root's children. But if there were an alternate path to the other child, the backtracking would never reach the root – we would take a different path. Thus, the root having 2 or more children means that the only way from one child to the other child is through the root, and the root is an articulation point.

  11. Determining Articulation points We can change the node-visit function in our original DFS into a function that returns the highest point in the tree (lowest val value) seen during the search: int visit(int* val, int k, int & id) { nodePtr t; int m, min; val[k] = ++id; min = id; t = adj[k]; while (t != z) { if (val[t->v] == 0) { m = visit(val, t->v, id); min = (m < min) ? m : min; // if (m >= val[k]) cout << name(k); } else { if (val[t->v] < min) min = val[t->v]; } t = t->next; } return min; }

  12. Determining Articulation points - runtime The biconnected components of a graph can be found in linear time, because it is based on the DFS procedure, which runs in time proportional to V+E. A similar program based on adjacency matrices would run in O(V2) steps.

  13. A H I G B C K J D E L M F Union-Find Algorithms In some applications, we may want to know simply whether or not a vertex x is connected to a vertex y in a graph without due regard to the actual path connecting them. Efficient algorithms that solve this problem are based on sets (collections of objects). Graphs correspond to sets of objects in a natural way: vertices correspond to objects and edges mean “is in the same set as”. {A B C D E F G} {H I } {J K L M }

  14. A H I G B C K J D E L M F Union-Find Algorithms “Is x in the same set as y”  “is vertex x connected to vertex y” { A B C D E F G } {H I } {J K L M }

  15. Union-Find Algorithms Given an adjacency list representation of a graph, and using DFS to assign to each vertex the index of its connected components, one can answer “is x connected to y?” with two array accesses. However here we consider dynamic operations. That is, we can accept arbitrary new edges intermixed with the questions. Addition of a new edge corresponds to a set union and we will call the queries find operations.

  16. Union-Find Algorithms - Prerequisites Objective: write a function that can check if two vertices x and y are in the same set (in the same connected component – in the graph representation), and if not, can put them in the same set (put an edge between them in the graph). We will use a forest of trees which turns out to be efficient at supporting union and find. We need to find out if two vertices belong to the same tree and to be able to combine two trees into one. To this end, we will us a dad array, which indicates parentship of a node.

  17. A H I G B C K J D E L M F Union-Find Algorithms Let’s trace the forest constructed when edges are processed in this order: AG AB AC LM JM JL JK ED FD HI FE AF GE GC GH JG LG

  18. Union-Find Algorithms AG AB AC LM JM JL JK ED FD HI FE AF GE GC GH JG LG

  19. Union-Find Algorithms AG AB AC LM JM JL JK ED FD HI FE AF GE GC GH JG LG

  20. Union-Find Algorithms Progress of building the dad array. Each row shows the state of the dad array as edges are processes. The final state shows J as the root of the tree. The dad array contains, for each vertex, the index of its parent (with a 0 for root nodes). Final state

  21. Union-Find Algorithms bool find(int x, int y, bool union) { int i, j; i = x; while (dad[i] > 0) i = dad[i]; j = y; while (dad[j] > 0) j = dad[j]; if (union && (i!=j)) { dad[j] = i; return true; } return (i==j); } The function is called with x and y being the indexes of the nodes whose connectivity is sought. union indicates whether one should connect the two nodes.

More Related