Graph Connectivity This discussion concerns connected components of a graph. Previously, we discussed depth-first search (DFS) as a means of determining.

Slides:



Advertisements
Similar presentations
Chapter 5: Tree Constructions
Advertisements

Graph Algorithms Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 11Feb 07, 2014Carnegie Mellon University.
Lecture 15. Graph Algorithms
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
CS 312 – Graph Algorithms1 Graph Algorithms Many problems are naturally represented as graphs – Networks, Maps, Possible paths, Resource Flow, etc. Ch.
1 Section 9.4 Spanning Trees. 2 Let G be a simple graph. A spanning subtree of G is a subgraph of G containing every vertex of G –must be connected; contains.
TECH Computer Science Graphs and Graph Traversals  // From Tree to Graph  // Many programs can be cast as problems on graph Definitions and Representations.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Applications of graph traversals
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Data Structures & Algorithms Graph Search Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Makeup Lecture Chapter 23: Graph Algorithms Depth-First SearchBreadth-First.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Graphs.
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Introduction to Graphs
DAST 2005 Tirgul 11 (and more) sample questions. DAST 2005 Q.Let G = (V,E) be an undirected, connected graph with an edge weight function w : E→R. Let.
1 Data Structures and Algorithms Graphs I: Representation and Search Gal A. Kaminka Computer Science Department.
COMP171 Depth-First Search.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Applications of Depth-First Search
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
2/10/03Tucker, Sec Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
IS 2610: Data Structures Graph April 5, 2004.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Week -7-8 Topic - Graph Algorithms CSE – 5311 Prepared by:- Sushruth Puttaswamy Lekhendro Lisham.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Graph Search Computing 2 COMP s1. P ROBLEMS ON G RAPHS What kinds of problems do we want to solve on/via graphs? Is there a simple path from A to.
MA/CSSE 473 Day 12 Insertion Sort quick review DFS, BFS Topological Sort.
CSC 331: Algorithm Analysis Decompositions of Graphs.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
Graphs. 2 Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
1 Applications of BFS and DFS CSE 2011 Winter May 2016.
Graphs.
Union-find Algorithm Presented by Michael Cassarino.
Unit – V Graph theory. Representation of Graphs Graph G (V, E,  ) V Set of vertices ESet of edges  Function that assigns vertices {v, w} to each edge.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Graphs are collections of vertices and edges. Vertices are simple objects with associated names and other properties. Edges are connections between.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
Graphs. Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A,
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Topological Sort: Definition
Introduction to Graph Theory Lecture 17: Graph Searching Algorithms.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
 2004 SDU 1 Lecture5-Strongly Connected Components.
7 Finding Bridge in a Graph. What is a bridge ? A C D B F G E.
Chapter 05 Introduction to Graph And Search Algorithms.
Graph Representations And Traversals. Graphs Graph : – Set of Vertices (Nodes) – Set of Edges connecting vertices (u, v) : edge connecting Origin: u Destination:
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
5. Biconnected Components of A Graph If one city’s airport is closed by bad weather, can you still fly between any other pair of cities? If one computer.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
11 Graph Search Algorithms. 2 What parts of the graph are reachable from a given vertex ?
CS 361 – Chapter 13 Graph Review Purpose Representation Traversal Comparison with tree.
Lecture #13. Topics 1.The Graph Abstract Data Type. 2.Graph Representations. 3.Elementary Graph Operations.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Minimum Spanning Tree 8/7/2018 4:26 AM
Graph Algorithms Using Depth First Search
Biconnected Graph Articulation Points
Presentation transcript:

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.

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. J L M J L K M biconnectedNot biconnected

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. J L K M A BC G F D E H I

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}. JLKMABCGFDEHI

DFS revisited A BC G F D E A BC G F D E A BC G F D E A BC G F D E A BC G F D E A BC G F D E

A BC G F D E A B C G F D E A BC G F D E A BC G F D E

DFS results representation A BC G F D E A B C F E D G 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. Actual graphTraversal path

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). J L K M A BC G F D E H I A B F E D G C H I L J M K

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. J L K M A BC G F D E H I A B F E D G C H I L J M K

Determining Articulation points Root 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. J L K M A BC G F D E H I A B F E D G C H I L J M K

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; }

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(V 2 ) steps.

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”. J L K M A BC G F D E H I {A B C D E F G} {H I } {J K L M }

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

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.

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.

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 J L K M A BC G F D E H I

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

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

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

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.