CS483 Design and Analysis of Algorithms

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

CS Elementary Graph Algorithms

CS Elementary Graph Algorithms

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

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Strongly Connected Components. Andreas Klappenecker

Design and Analysis of Algorithms

Strongly Connected Components

Graphs: Connectivity. Jordi Cortadella and Jordi Petit Department of Computer Science

Finding Strongly Connected Components

1 Connected components in undirected graphs

Inf 2B: Graphs II - Applications of DFS

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

Design and Analysis of Algorithms

CS 473: Algorithms. Chandra Chekuri 3228 Siebel Center. Fall University of Illinois, Urbana-Champaign

Algorithm Design and Analysis

Lecture 3: Graphs and flows

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

22.3 Depth First Search

Depth First Search (DFS)

Midterm 1 for CS 170

23 DECOMPOSITION OF GRAPHS

Graph. Vertex. edge. Directed Graph. Undirected Graph

Graph Representation

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 5: SCC/BFS

Graph Algorithms (part 3 of CSC 282),

Lecture 22 Tuesday, April 10

Lecture 10. Finding strongly connected components

Graph representation

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

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

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

CS4800: Algorithms & Data Jonathan Ullman

Lecture 10: Strongly Connected Components, Biconnected Graphs

GRAPHS Lecture 19 CS2110 Spring 2013

DFS & STRONGLY CONNECTED COMPONENTS

Basic Graph Algorithms

Lecture 16: Directed Graphs

Question Points Score TOTAL 50

CS Elementary Graph Algorithms & Transform-and-Conquer

Homework Assignment #3 Graph

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search

Elementary Graph Algorithms

Graph Representations and Traversal

Fundamental Graph Algorithms Part Four

Graphs & Digraphs Tuesday, November 06, 2007

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

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).

Chapter 22 Elementary Graph Algorithms

CSE 331: Introduction to Algorithm Analysis and Design Graphs

CSC Intro to Intelligent Robotics, Spring Graphs

Graph Algorithms: Chapters Part 1: Introductory graph concepts

Introduction to Graphs. CS2110, Spring 2011 Cornell University

Graph: representation and traversal

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

Design and Analysis of Algorithms

Quiz 2 CS 3510 October 22, 2004

Announcements. HW3 is graded. Average is 81%

CS 125 Section #6 Graph Traversal and Linear Programs 10/13/14

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

Graph Algorithms (part 3 of CSC 282),

Graph Search. Algorithms & Models of Computation CS/ECE 374, Fall Lecture 15. Thursday, October 19, 2017

Copyright 2000, Kevin Wayne 1

CSC 111 Introduction to Computer Science (Section C)

Exercise 1. D-ary Tree

Graph Algorithms Using Depth First Search

Algorithms (V) Path in Graphs. Guoqiang Li. School of Software, Shanghai Jiao Tong University

Solutions to Midterm 2 - Monday, July 11th, 2009

ECE250: Algorithms and Data Structures Single Source Shortest Paths Bellman-Ford Algorithm

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

Chapter 22. Elementary Graph Algorithms

Algorithm Design and Analysis

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

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:

CS2 Algorithms and Data Structures Note 9

Link to starter code:

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

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

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

Lecture 27: Learning from relational data

Lecture 9 Graph Traversal

1 Start with each vertex being its own component. 2 Merge two components into one by choosing the light edge

Elementary Graph Algorithms CSE 6331

Depth First Search (DFS)

Outline. Graphs. Divide and Conquer.

Total Score /1 /20 /41 /15 /23 Grader

Introduction to Algorithms

CS Divide and Conquer

CS Algorithms and Complexity

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

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

CSE 373: Data Structures and Algorithms

CSCE 750, Fall 2002 Notes 6 Page Graph Problems ffl explore all nodes (breadth first and depth first) ffl find the shortest path from a given s

Directed Graphs (II) Hwansoo Han

More Graph Algorithms

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

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

Info 2950, Lecture 16

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Transcription:

CS483 Design and Analysis of Algorithms Lecture 9 Decompositions of Graphs Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm - 6:00pm or by appointments Course web-site: http://www.cs.gmu.edu/ lifei/teaching/cs483 fall08/ Figures unclaimed are from books Algorithms and Introduction to Algorithms 1 / 18

Decomposition of Graphs 1 Why Graphs? 2 Depth-First Search 3 Topological Sorting 4 Strongly Connected Components (SCC) 2 / 18

Why Graphs? 3 / 18

Why Graphs? 4 / 18

Graphs 1 A graph G = (V, E) is specified by a set of vertices (nodes) V and edges E between selected pairs of vertices 2 Edges are symmetric undirected graph 3 Directions over edges directed graph 4 E.g., political maps, exam conflicts, World Wide Web, etc. 5 / 18

Graph Representation http://msdn2.microsoft.com/en-us/library/ 6 / 18

Graph Traversal Exploring a graph is rather like navigating a maze Which parts of the graph are reachable from a given vertex? 7 / 18

Depth-First Search Input: Graph G = (V, E), vertex s V Output: All vertices u reachable from s function DFS(G) for all v V visited(v) = false; for all v V if not visited(v) explore(v); function explore(g, v) visited(v) = true; for each edge (v, u) E if not visited(u) explore(u); 8 / 18

Depth-First Search 9 / 18

Analysis of DFS Theorem All nodes reachable from s can be found via DFS Proof.? Theorem The overall running time of DFS is O( V + E ) Proof. 1 The time initializing each vertex is O( V ) 2 Each edge (u, v) E is examined twice, once exploring u and once exploring v. Therefore takes O( E ) time 10 / 18

Topological Sorting An Application of DFS Input: a directed acyclic graph (DAG) G output: A linear ordering of all its vertices, such that if G contains an edge (u, v), then, u appears before v in the ordering 11 / 18

Topological Sorting An Application of DFS 1 Run DFS to get (startingtime, finishingtime) 12 / 18

Topological Sorting An Application of DFS 1 Run DFS to get (startingtime, finishingtime) 2 List nodes in reverse order of their finishing time 13 / 18

Announcements 1 Assignment 4 is due on this Wednesday. 2 There is a review class on October 8th (this Wednesday): Chapters 0 4.3 of DPV, Chapter 5 of CLSR. Covers: Solutions of assignment 4 and a few selected problems with their solutions. Later submission of assignment 4 will not be accepted. 3 Next Monday (October 13th) is a holiday. (Monday class meets Tuesday). 4 Midterm is scheduled on October 14th (next TUESDAY), 1:30pm - 2:45pm, Innovation Hall 136. 5 The class on October 15th (next Wednesday) is canceled. 14 / 18

Strongly Connected Components in Directed Graphs Definition Two nodes u and v of a directed graph are connected if there is a path from u to v and a path from v to u. Remark Connectivity in undirected graphs is straightforward. Remark Every directed graph is a directed acyclic graph (DAG) of its strongly connected components (disjoint sets of V ) 15 / 18

How to Find SCC? Remark If the explore subroutine starts at node u, then it will terminate precisely when all nodes reachable from u have been visited. If we call explore on a node that lies somewhere in a sink strongly connected component, then we will retrieve exactly that component What can we learn? 1 How do we find a node that we know for sure lies in a sink strongly connected component? 2 How do we continue once this first component has been discovered? Remark The node that receives the highest ending time (i.e., post number) in a depth-first search must lie in a source strongly connected component. 16 / 18

How to Find SCC? Remark If C and C are strongly connected components, and there is an edge from a node in C to a node in C, the the highest post number in C is larger than the highest post number in C What can we learn? Remark The strongly connected components can be linearized by arranging them in decreasing order of their highest post numbers. Remark The reverse graph G R, the same as G but with all edges reversed, has the same SCC as G. 17 / 18

Strongly Connected Components 1 Run depth-first search on G R 2 Run the undirected connected components algorithm on G, and during the depth-first search, process the vertices in decreasing order of their finishing time from step 1 18 / 18