Elementary Graph Algorithms CSE 6331

Similar documents
Graph Algorithms Using Depth First Search

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

15-451/651: Design & Analysis of Algorithms October 5, 2017 Lecture #11: Depth First Search and Strong Components last changed: October 17, 2017

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

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

CS/COE

Representations of Graphs

Undirected Graphs. Hwansoo Han

Graph Algorithms. Definition

Graph. Vertex. edge. Directed Graph. Undirected Graph

DFS & STRONGLY CONNECTED COMPONENTS

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search

Design and Analysis of Algorithms

Depth-first search, the problem

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

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

Depth-first search in undirected graphs What parts of the graph are reachable from a given vertex?

Graph Representation

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

Basic Graph Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

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

Algorithms: Lecture 10. Chalmers University of Technology

Graphs. Motivations: o Networks o Social networks o Program testing o Job Assignment Examples: o Code graph:

Konigsberg Bridge Problem

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

W4231: Analysis of Algorithms

Algorithmic Aspects of Communication Networks

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

BACKGROUND: A BRIEF INTRODUCTION TO GRAPH THEORY

Week 5. 1 Analysing BFS. 2 Depth-first search. 3 Analysing DFS. 4 Dags and topological sorting. 5 Detecting cycles. CS 270 Algorithms.

COT 6405 Introduction to Theory of Algorithms

CS302 - Data Structures using C++

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

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

Searching in Graphs (cut points)

Announcements. HW3 is graded. Average is 81%

Strongly Connected Components

Lecture 10: Strongly Connected Components, Biconnected Graphs

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 16. Graph Search Algorithms. Recall BFS

Inf 2B: Graphs II - Applications of DFS

Graph Search. Adnan Aziz

Applications of BDF and DFS

Graph: representation and traversal

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

Proof: if not f[u] < d[v], then u still grey while v is being visited. DFS visit(v) will then terminate before DFS visit(u).

Trees Algorhyme by Radia Perlman

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

Graph Biconnectivity

Unweighted Graphs & Algorithms

CS 270 Algorithms. Oliver Kullmann. Analysing BFS. Depth-first search. Analysing DFS. Dags and topological sorting.

Copyright 2000, Kevin Wayne 1

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

Basic Graph Algorithms (CLRS B.4-B.5, )

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

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

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Graph Algorithms: Chapters Part 1: Introductory graph concepts

Chapter 22. Elementary Graph Algorithms

CSC Intro to Intelligent Robotics, Spring Graphs

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

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

Data Structures. Elementary Graph Algorithms BFS, DFS & Topological Sort

Graph traversal is a generalization of tree traversal except we have to keep track of the visited vertices.

CS 270 Algorithms. Oliver Kullmann. Breadth-first search. Analysing BFS. Depth-first. search. Analysing DFS. Dags and topological sorting.


Minimum Spanning Trees Ch 23 Traversing graphs

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search

Outline. Graphs. Divide and Conquer.

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

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

CSE 101. Algorithm Design and Analysis Miles Jones and Russell Impagliazzo Miles Office 4208 CSE Building

Strongly connected: A directed graph is strongly connected if every pair of vertices are reachable from each other.

Fundamental Graph Algorithms Part Three

Graph and Digraph Glossary

Design and Analysis of Algorithms

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Dynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs).

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

Graph Search Methods. Graph Search Methods

DARSHAN INST. OF ENGG. & TECH.

Depth First Search (DFS)

Graph representation

Chapter 6. GRAPHS. Figure 6.1 : The bridges of Koenigsberg

CS 310 Advanced Data Structures and Algorithms

March 20/2003 Jayakanth Srinivasan,

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

Homework No. 4 Answers

Data Structures and Algorithms. Chapter 7. Graphs

Graphs. Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1

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

csci 210: Data Structures Graph Traversals

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Algorithm Design and Analysis

CSE 421 DFS / Topological Ordering

st-orientations September 29, 2005

Elementary Graph Algorithms

Transcription:

Elementary Graph Algorithms CSE 6331 Reading Assignment: Chapter 22 1 Basic Depth-First Search Algorithm procedure Search(G = (V, E)) // Assume V = {1, 2,..., n} // // global array visited[1..n] // visited[1..n] 0; for i 1 to n if visited[i] = 0 then call dfs(i) procedure df s(v) visited[v] 1; for each node w such that (v, w) E do if visited[w] = 0 then call dfs(w) Questions How to implement the for-loop (i) if an adjacency matrix is used to represent the graph and (ii) if adjacency lists are used? How many times is dfs called in all? How many times is if visited[ ] = 0 executed in all? What s the over-all time complexity of the command for each node w such that (v, w) E Time complexity Using adjacency matrix: O(n 2 ) Using adjacency lists: O( V + E ) 1

Definitions Depth first tree/forest, denoted as G π Tree edges: those edges in G π Forward edges: those non-tree edges (u, v) connecting a vertex u to a descendant v. Back edges: those edges (u, v) connecting a vertex u to an ancestor v. Cross edges: all other edges. If G is undirected, then there is no distinction between forward edges and back edges. Just call them back edges. 2

2 Depth-First Search Revisited procedure Search(G = (V, E)) // Assume V = {1, 2,..., n} // time 0; d[1..n] 0; /* d stands for discovery time */ for i 1 to n if d[i] = 0 then call dfs(i) procedure df s(v) d[v] time time + 1; for each node w such that (v, w) E do if d[w] = 0 then call dfs(w); f[v] time time + 1 /* f stands for finishing time */ 3

3 Topological Sort Problem: given a directed acyclic graph G = (V, E), obtain a linear ordering of the vertices such that for every edge (u, v) E, u is ahead of v in the ordering. Solution: Use depth-first search, with an initially empty list L. At the end of procedure dfs(v), insert v to the front of L. L gives a topological sort of the vertices. Observation: the list of nodes in the descending order of finishing times yields a topological sort. 4

4 Strongly Connected Components A directed graph is strongly connected if for every two nodes u and v there is a path from u to v and one from v to u. Decide if a graph G is strongly connected: G is strongly connected iff (i) every node is reachable from node 1 and (ii) node 1 is reachable from every node. The two conditions can be checked by applying dfs(1) to G and to G T, where G T is the graph obtained from G by reversing the edges. A subgraph G of a directed graph G is said to be a strongly connected component of G if G is strongly connected and is not contained in any other strongly connected subgraph. An interesting problem is to find all strongly connected components of a directed graph. Each node belongs in exactly one component. each component by its vertices. So, we identify The component containing v equals {dfs(v) on G} {dfs(v) on G T }, where {dfs(v) on G} denotes the set of all vertices visited during dfs(v) on G. 5

Ideas: If C is a strongly connected component, define f(c) = max{f(x) : x C}. Let C, C be two distinct strongly connected components. If there is an edge in G from C to C, then f(c) > f(c ). (In G, edges between two strongly connected components go from the component with higher finishing time to the component with lower finishing time.) Let C, C be two distinct strongly connected components. If there is an edge in G T from C to C, then f(c) > f(c ). (In G T, edges between two strongly connected components go from the component with lower finishing time to the component with higher finishing time.) Algorithm: 1. Apply depth-first search to G and compute f[u] for each node. 2. Compute G T. 3. Apply the basic depth-first search to G T : visited[1..n] 0 for each vertex u in decreasing order of f[u] do if visited[u] = 0 then call dfs(u) 4. The vertices on each tree in the depth-first forest of Step 3 form a strongly connected component. 6

5 Articulation Points and Biconnected Components 5.1 Definitions Let G be a connected, undirected graph. An articulation point of G is a vertex whose removal will disconnect G. A bridge of G is an edge whose removal will disconnect G Definition: A (connected) graph is biconnected if it contains no articulation points. A biconnected component of G is a maximal biconnected subgraph. Each edge belongs to exactly one biconnected component. 7

5.2 Identifying All Articulation Points Let G π be any depth-first tree of G. An edge in G is a back edge iff it is not in G π. The root of G π children. is an articulation of G iff it has at least two A non-root vertex v in G π is an articulation point of G iff v has a child w in G π such that no vertex in subtree(w) is connected to a proper ancestor of v by a back edge. (subtree(w) denotes the subtree rooted at w in G π.) Define low[w] = min { d[w] d[x] : x is joined to some vertex in subtree(w) by a back edge A non-root vertex v in G π is an articulation point of G iff v has a child w such that low[w] d[v]. 8

Note that d[v] low[v] = min d[w] : w is connected to v by a back edge low[w] : w is a child of v Computing low[v] for each vertex v: procedure Art(v, u) /* visit v from u */ low[v] d[v] time time + 1; for each vertex w u such that (v, w) E do if d[w] = 0 then call Art(w, v) low[v] min{low[v], low[w]} else low[v] min{low[v], d[w]} endif endfor Initial call: Art(1, 0). 9

Problem: Print all articulation points. procedure Art(v, u) /* visit v from u */ low[v] d[v] time time + 1; for each vertex w u such that (v, w) E do if d[w] = 0 then call Art(w, v) low[v] min{low[v], low[w]} if (d[v] = 1) and (d[w] 2) then print v is an articulation point if (d[v] 1) and (low[w] d[v]) then print v is an articulation point else low[v] min{low[v], d[w]} endif endfor 10

Problem: Identify all biconnected components. procedure Art(v, u) /* visit v from u */ low[v] d[v] time time + 1; for each vertex w u such that (v, w) E do if d[w] < d[v] then add (v, w) to Stack if d[w] = 0 then call Art(w, v) low[v] min{low[v], low[w]} if low[w] d[v] then Pop off all edges from Stack till edge (v, w) //these edges form a biconnected component// else low[v] min{low[v], d[w]} endif endfor 11