Searching in Graphs (cut points)

Similar documents
Applications of BDF and DFS

Trees. Arash Rafiey. 20 October, 2015

Graph Algorithms Using Depth First Search

Algorithms: Lecture 10. Chalmers University of Technology

Graph Algorithms. Imran Rashid. Jan 16, University of Washington

Copyright 2000, Kevin Wayne 1

Lecture 3: Graphs and flows

Algorithm Design and Analysis

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

Depth-First Search Depth-first search (DFS) is another way to traverse the graph.

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Undirected Graphs. Hwansoo Han

3.4 Testing Bipartiteness

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

Lecture 10 Graph algorithms: testing graph properties

Search means finding a path or traversal between a start node and one of a set of goal nodes. Search is a study of states and their transitions.

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

CS 361 Data Structures & Algs Lecture 13. Prof. Tom Hayes University of New Mexico

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

CS Lunch. Grace Hopper??? O()? Slides06 BFS, DFS, Bipartite.key - October 3, 2016

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

Cut vertices, Cut Edges and Biconnected components. MTL776 Graph algorithms

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Algorithmic Aspects of Communication Networks

March 20/2003 Jayakanth Srinivasan,

Graph. Vertex. edge. Directed Graph. Undirected Graph

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

MAL 376: Graph Algorithms I Semester Lecture 1: July 24

3.1 Basic Definitions and Applications

Goals! CSE 417: Algorithms and Computational Complexity!

CSE 421 DFS / Topological Ordering

Graph Algorithms. Definition

CS/COE


3.1 Basic Definitions and Applications. Chapter 3. Graphs. Undirected Graphs. Some Graph Applications

Graphs. Part I: Basic algorithms. Laura Toma Algorithms (csci2200), Bowdoin College

CS 310 Advanced Data Structures and Algorithms

Graph Representations and Traversal

Elementary Graph Algorithms CSE 6331

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

Chapter 3. Graphs. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

CSE 417: Algorithms and Computational Complexity. 3.1 Basic Definitions and Applications. Goals. Chapter 3. Winter 2012 Graphs and Graph Algorithms

Trees Algorhyme by Radia Perlman

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

W4231: Analysis of Algorithms

Definition For vertices u, v V (G), the distance from u to v, denoted d(u, v), in G is the length of a shortest u, v-path. 1

Definition Example Solution

CS781 Lecture 2 January 13, Graph Traversals, Search, and Ordering

Algorithm Design and Analysis

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

Jana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides

CS 280 Problem Set 10 Solutions Due May 3, Part A

Exercise set 2 Solutions

MTL 776: Graph Algorithms Lecture : Matching in Graphs

CSE 417: Algorithms and Computational Complexity

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

Objec&ves. Wrap up: Implemen&ng BFS and DFS Graph Applica&on: Bipar&te Graphs. Get out your BFS implementa&on handouts. Feb 2, 2018 CSCI211 - Sprenkle

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

Graph Search Methods. Graph Search Methods

3.1 Basic Definitions and Applications

Graph Search Methods. Graph Search Methods

Mathematics Masters Examination

This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.

st-orientations September 29, 2005

Flow Graph Theory. Depth-First Ordering Efficiency of Iterative Algorithms Reducible Flow Graphs

Graph: representation and traversal

COT 6405 Introduction to Theory of Algorithms

DARSHAN INST. OF ENGG. & TECH.

DFS Search on Undirected Graphs. Algorithm : Design & Analysis [13]

Chapter 20: Binary Trees

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

DFS & STRONGLY CONNECTED COMPONENTS

22.3 Depth First Search

Lecture 9 Graph Traversal

CS4800: Algorithms & Data Jonathan Ullman

Graphs. A graph is a data structure consisting of nodes (or vertices) and edges. An edge is a connection between two nodes

GRAPHICAL ALGORITHMS. UNIT _II Lecture-12 Slides No. 3-7 Lecture Slides No Lecture Slides No

Trees. Truong Tuan Anh CSE-HCMUT

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

LECTURE 26 PRIM S ALGORITHM

implementing the breadth-first search algorithm implementing the depth-first search algorithm

CS521 \ Notes for the Final Exam

Computational Optimization ISE 407. Lecture 19. Dr. Ted Ralphs

GRAPHS (Undirected) Graph: Set of objects with pairwise connections. Why study graph algorithms?

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

國立清華大學電機工程學系. Outline

Konigsberg Bridge Problem

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

CSE 4/531 Solution 3

4 Basics of Trees. Petr Hliněný, FI MU Brno 1 FI: MA010: Trees and Forests

Backtracking. Chapter 5

Introduction to Computers and Programming. Concept Question

Plan. CMPSCI 311: Introduction to Algorithms. Recall. Adjacency List Representation. DFS Descriptions. BFS Description

Transcription:

0 November, 0

Breath First Search (BFS) in Graphs In BFS algorithm we visit the verices level by level. The BFS algorithm creates a tree with root s. Once a node v is discovered by BFS algorithm we put an edge from v to all the nodes u that have not been considered. This way v is set to be the father of node u.

BFS (s). Set Discover[s]=true and Discover[v]=false for all other v. Set L[0] = {s}. Set layer counter i=0 4. Set T = 4. While L[i] is not empty. Initialize empty set L[i + ] 6. For each node u L[i] 7. Consider each edge uv 8. If Discover[v] = false then 9. Set Discover[v] = true 0. Add edge uv to T. Add v to the list L[i + ], and increase i by one

7 4 8 4 7 8 4 7 8 6 6

7 4 8 4 7 8 4 7 8 6 6

7 4 8 4 7 8 4 7 8 6 6

7 4 8 4 7 8 4 7 8 6 6

BFS running time ) If we represent the graph G by adjacency matrix then the running time of BFS algorithm is O(n ), where n is the number of nodes. ) If we represent the graph G by link lists then the running time of BFS algorithm is O(m + n), where m is the number of edges and n is the number of nodes.

Bipartite Testing Problem : Given a graph G decide whether G is bipartite or not. A graph G is bipartite iff G does not contain an odd cycle.

Bipartite Testing Problem : Given a graph G decide whether G is bipartite or not. A graph G is bipartite iff G does not contain an odd cycle. Solution (Using BFS) Start with node s and color it with red. Next color the neighbors of s by blue. Next color the neighbors of neighbors of s by red and so on. If at the end there is an edge whose end points receive the same color G is not bipartite.

Bipartite Testing Problem : Given a graph G decide whether G is bipartite or not. A graph G is bipartite iff G does not contain an odd cycle. Solution (Using BFS) Start with node s and color it with red. Next color the neighbors of s by blue. Next color the neighbors of neighbors of s by red and so on. If at the end there is an edge whose end points receive the same color G is not bipartite. This is essentially is the BFS algorithm. We color the nodes in L 0 by red and the nodes in L by blue and the nodes in L by red and so on. Next we read each edge uv of G. If both u, v have the same color then G is not bipartite. Otherwise G is bipartite.

Lemma Let G be a connected graph, and let L 0, L, L,..., L k be the layers produced by BFS algorithm starting at node s. (i) There is no edge of G joining two nodes of the same layer. In this case G is bipartite and L 0, L,..., L i can be colored red and the nodes in odd layers can be colored blue. (ii) There is an edge of G joining two nodes of the same layer. In this case G contains an odd cycle and G is not bipartite. Proof : Suppose (i) happens. In this case the red nodes and blue nodes give a bipartition, and all the edges of G are between the red and blue nodes.

Suppose (ii) happens. Suppose x, y L j and xy E(G). ) By definition there is a path P from s to x of length j and there is a path Q from s to y of length j.

Suppose (ii) happens. Suppose x, y L j and xy E(G). ) By definition there is a path P from s to x of length j and there is a path Q from s to y of length j. ) Let i be the maximum index such that there is z L(i) and z is in the intersection of P and Q, i.e. z P Q and z L(i).

Suppose (ii) happens. Suppose x, y L j and xy E(G). ) By definition there is a path P from s to x of length j and there is a path Q from s to y of length j. ) Let i be the maximum index such that there is z L(i) and z is in the intersection of P and Q, i.e. z P Q and z L(i). ) Portion of P, say P from z to x has length j i and portion of Q, say Q from z to y has length j i. 4) By adding xy edges into P, Q we get a cycle of length (j i) + + (j i) which is of odd length.

Depth-First Search (backtracking approach) We don t visit the nodes level by level! As long as there is an unvisited node adjacent to the current visited node we continue! Once we are stuck, trace back and go to a different branch!

Depth-First Search (backtracking approach) We don t visit the nodes level by level! As long as there is an unvisited node adjacent to the current visited node we continue! Once we are stuck, trace back and go to a different branch! DFS (u). Mark u as Explored and add u to R. For every edge uv. If v is not Explored then call DFS (v)

7 4 8 6 4 6

7 4 8 6 4 6

7 4 8 6 4 6

7 4 8 6

7 4 8 6 4 4 6

4 7 8 6 4 6 4 6 7 4 6 7 8

DFS running time ) If we represent the graph G by adjacency matrix then the running time of BFS algorithm is O(n ), where n is the number of nodes. ) If we represent the graph G by link lists then the running time of BFS algorithm is O(m + n), where m is the number of edges and n is the number of nodes.

Biconnected Components Let G = (V, E) be a loop-free connected undirected graph. A vertex v in G is called an articulation point if κ(g v) > κ(g). G v has more connected components than v. A loop-free connected undirected graph with no articulation points is called biconnected.

Lemma Let G = (V, E) be a loop-free connected undirected graph with T = (V, E ) a DFS spanning tree for G. If ab E but ab E, then a is either an ancestor or a descendant of b in the tree.

Lemma Let G = (V, E) be a loop-free connected undirected graph with T = (V, E ) a DFS spanning tree for G. If ab E but ab E, then a is either an ancestor or a descendant of b in the tree. Lemma Let G = (V, E) be a loop-free connected undirected graph with T = (V, E ) a DFS spanning tree for G. If r is a root of T, then r is an articulation point of G if and only if r has at least two children in T.

Lemma Let G = (V, E) be a loop-free connected undirected graph with T = (V, E ) a DFS spanning tree for G. If ab E but ab E, then a is either an ancestor or a descendant of b in the tree. Lemma Let G = (V, E) be a loop-free connected undirected graph with T = (V, E ) a DFS spanning tree for G. If r is a root of T, then r is an articulation point of G if and only if r has at least two children in T. Lemma Let G = (V, E) be a loop-free connected undirected graph with T = (V, E ) a DFS spanning tree for G. Let r be a root of T, and let v V, v r. Then v is an articulation point of G if and only if there exists a child c of v with no back edge from a vertex in T c (the subtree rooted at c) to an ancestor of v.

Finding Articulation Points ) We traverse the graph in DFS (preorder) manner. ) For vertex x of G define dfi(x) to be the index of x in DFS (time we visit x). If y is a descendant of x then dfi(x) < dfi(y).

Finding Articulation Points ) We traverse the graph in DFS (preorder) manner. ) For vertex x of G define dfi(x) to be the index of x in DFS (time we visit x). If y is a descendant of x then dfi(x) < dfi(y). ) Define low(x) = min{dfi(y) y is adjacent in G to either x or a descendant of x}

Let z be the parent of x in T. Then : ) low(x) = dfi(z) : In this case T x contains no vertex that is adjacent to an ancestor of z (by back edge). Hence z is an articulation point of G. If T x contains no articulation points, then T x together with edge zx is a biconnected component of G. Remove T x and the edge xz and apply on the remaining subtree of T.

Let z be the parent of x in T. Then : ) low(x) = dfi(z) : In this case T x contains no vertex that is adjacent to an ancestor of z (by back edge). Hence z is an articulation point of G. If T x contains no articulation points, then T x together with edge zx is a biconnected component of G. Remove T x and the edge xz and apply on the remaining subtree of T. ) If low(x) < dfi(z) : there is a descendant of z in T x that is joined (by a back edge in G) to an ancestor of z.

Algorithm for Articulation Points ) Find a DFS ordering x, x,..., x n of the vertices of G. ) Start from x n and continue to x n, x n,..., x and determine low(x j ) as follows : a) low (x j ) = min{dfi(z) z is adjacent in G to x j } b) If c, c,..., c m are children of x j, then low(x j ) = min{low (x j ), low (c ), low (c ),..., low (c m )} ) Let w j be the parent of x j in T. If low(x j ) = dfi(w j ) then w j is an articulation point of G, unless w j is the root of T and w j has no child in T other than x j. Moreover, in either situation the subtree rooted at x j together with the edge w j x j is part of a biconnected component of G.

a e d c b() d() e(4) g f b c() a() f(6) h g(7) h(8) d(,) d(,) d d b(,) c(,) e(,) a(4,) f(,) g(6,6) c(,) b(,) e(4,) a(,) f(6,) g(7,6) c b f g f a e g h(7,7) h(8,7) h