CS 312: Algorithm Analysis Lecture #16: Strongly Connected Components This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.

Slides:



Advertisements
Similar presentations
CSE 211 Discrete Mathematics
Advertisements

Introduction to Algorithms Graph Algorithms
Graph Algorithms Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 11Feb 07, 2014Carnegie Mellon University.
What is a graph ? G=(V,E) V = a set of vertices E = a set of edges edge = unordered pair of vertices
Graphs - II Algorithms G. Miller V. Adamchik CS Spring 2014 Carnegie Mellon University.
Topological Sort Topological sort is the list of vertices in the reverse order of their finishing times (post-order) of the depth-first search. Topological.
1 Strongly connected components. 2 Definition: the strongly connected components (SCC) C 1, …, C k of a directed graph G = (V,E) are the largest disjoint.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
1 Chapter 22: Elementary Graph Algorithms IV. 2 About this lecture Review of Strongly Connected Components (SCC) in a directed graph Finding all SCC (i.e.,
More Graphs COL 106 Slides from Naveen. Some Terminology for Graph Search A vertex is white if it is undiscovered A vertex is gray if it has been discovered.
CS 312 – Graph Algorithms1 Graph Algorithms Many problems are naturally represented as graphs – Networks, Maps, Possible paths, Resource Flow, etc. Ch.
Graphs – Depth First Search ORD DFW SFO LAX
CS 3343: Analysis of Algorithms Lecture 24: Graph searching, Topological sort.
Tirgul 8 Graph algorithms: Strongly connected components.
16a-Graphs-More (More) Graphs Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
CS 473Lecture 151 CS473-Algorithms I Lecture 15 Graph Searching: Depth-First Search and Topological Sort.
David Luebke 1 5/20/2015 CS 332: Algorithms Graph Algorithms.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Graph Traversals Reading Material: Chapter 9. Graph Traversals Some applications require visiting every vertex in the graph exactly once. The application.
Testing for Connectedness and Cycles
1 Data Structures DFS, Topological Sort Dana Shapira.
Lecture 10 Topics Application of DFS Topological Sort
CSE 780 Algorithms Advanced Algorithms Graph Alg. DFS Topological sort.
Tirgul 11 BFS,DFS review Properties Use. Breadth-First-Search(BFS) The BFS algorithm executes a breadth search over the graph. The search starts at a.
CS344: Lecture 16 S. Muthu Muthukrishnan. Graph Navigation BFS: DFS: DFS numbering by start time or finish time. –tree, back, forward and cross edges.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Elementary graph algorithms Chapter 22
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
COSC 3101A - Design and Analysis of Algorithms 10
Spring 2015 Lecture 10: Elementary Graph Algorithms
CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Dijkstra’s Algorithm. Announcements Assignment #2 Due Tonight Exams Graded Assignment #3 Posted.
Discussion #32 1/13 Discussion #32 Properties and Applications of Depth-First Search Trees.
Graphs David Kauchak cs302 Spring DAGs Can represent dependency graphs underwear pants belt shirt tie jacket socks shoes watch.
CSC 413/513: Intro to Algorithms Graph Algorithms DFS.
Algorithm for obtaining the connected components of a graph Samia Qader 252a-az HW # 6 all examples obtained from LEDA software in directory: 252a/handout/demo/graphwin/graphwin.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Jan Topological Order and SCC Edge classification Topological order Recognition of strongly connected components.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Depth-First Search Lecture 21: Graph Traversals
David Luebke 1 1/25/2016 CSE 207: Algorithms Graph Algorithms.
Properties and Applications of Depth-First Search Trees and Forests
Graphs & Paths Presentation : Part II. Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent.
Strongly Connected Components for Directed Graphs Kelley Louie Credits: graphs by /demo/graphwin/graphwin.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
CS 312: Algorithm Design & Analysis Lecture #29: Network Flow and Cuts This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Hw. 6: Algorithm for finding strongly connected components. Original digraph as drawn in our book and in class: Preorder label : Postorder label Nodes:
11 Graph Search Algorithms. 2 What parts of the graph are reachable from a given vertex ?
November 22, Algorithms and Data Structures Lecture XII Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
Graph Algorithms – 2. graphs Parenthesis Theorem Theorem 22.7 For all u, v, exactly one of the following holds: 1. d[u] < f [u] < d[v] < f [v] or.
CS 3343: Analysis of Algorithms Lecture 24: Graph searching, Topological sort.
Introduction to Algorithms
Breadth-First Search (BFS)
Graphs – Breadth First Search
Tracing An Algorithm for Strongly Connected Components that uses Depth First Search Graph obtained from Text, page a-al: Geetika Tewari.
Main algorithm with recursion: We’ll have a function DFS that initializes, and then calls DFS-Visit, which is a recursive function and does the depth first.
Chapter 3. Decompositions of Graphs
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Graph Algorithms Using Depth First Search
Many slides here are based on E. Demaine , D. Luebke slides
CS 3343: Analysis of Algorithms
Lecture 10 Algorithm Analysis
Advanced Algorithms Analysis and Design
Elementary graph algorithms Chapter 22
Graph Representation (23.1/22.1)
Presentation transcript:

CS 312: Algorithm Analysis Lecture #16: Strongly Connected Components This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative Commons Attribution-Share Alike 3.0 Unported License Slides by: Eric Ringger, adapting figures from Dasgupta et al.

Objectives  Understand how to linearize a DAG  Introduce the idea of connectedness among vertices in Directed Graphs  Introduce the algorithm for finding Strongly Connected Components

Cycles  How do you detect a cycle in a directed graph?  Property: A directed graph has a cycle if and only if its depth-first search reveals a back edge.  Otherwise: a Directed Acyclic Graph (DAG)

Sources, Sinks, Linearization DFS Search Forest: Linearized DAG: 0. Define order; 1. DFS; 2. Read off post-order values in reverse order Analysis:

Sources, Sinks, Linearization DFS Search Forest: Linearized DAG: 0. Define order; 1. DFS; 2. Read off post-order values in reverse order Analysis:

Sources, Sinks, Linearization  Property: In a DAG, every edge leads to a vertex with a smaller post number.  Property: Every DAG has at least one source (a node with 0 in-degree).  Property: Every DAG has at least one sink (a node with 0 out-degree).  How to prove these?

Vertex Many Kinds of Connectedness Graphs Undirected Directed Edge Vertex Edge Connected components Biconnected components Strongly connected components Similar to biconnected components

Connectivity in Directed Graphs  Two nodes u and v of a directed graph are connected iff there is a path from u to v and a path from v to u.  Each vertex v is connected to itself.  Defines an equivalence relation!  This relation partitions V into disjoint sets that we call strongly connected components.  Equivalence classes under the above relation

Example Meta-graph:

Example Meta-graph:

Meta-Graph

Property: Every directed graph is a DAG of its strongly connected components.

How would you find SCCs?

 Idea 1: run DFS, identify back-edges to find cycles, post-process  Idea 2: run DFS, identify back-edges to find cycles, merge cycles  How to analyze?  We’re going to go take a different direction …

Finding Strongly Connected Components  To understand the algorithm for finding SCCs, you need to understand the following:  Pre and post numbering in DFS  Meta-graph created by representing each SCC with a single meta-node.  The meta-graph is a DAG and could therefore be linearized using DFS.

Finding SCCs  Goal: Given a directed graph, find all of the SCCs  Big Idea:  A: Find a (vertex in a) sink SCC  B: Work back to find the other SCCs  How do you find a sink SCC?  Finding a sink (node) in a DAG is easy  But what about when there are cycles?  Problem A seems hard, so solve problem A’ first:  Finding a node in a source SCC of a directed graph could be easier.  A’: find a source SCC on the “reverse graph”

Reverse Graph G To find a sink, identify a source SCC of the reverse graph G R ! GRGR Metagraph of G R

Insights  Property: The node that receives the highest post number in a depth-first search must lie in a source strongly connected component.  Property: If C and C’ are strongly connected components, and there is an edge from a node in C to a node in C’, then the highest post number in C is bigger than the highest post number in C’.  Consequence: The strongly connected components can be linearized by arranging them in decreasing order of their post numbers.

Step 1  Reverse the graph to produce G R  Necessary to do the reversal explicitly?  Run depth-first search on G R

Problem 3.4 (ii)

Step 2  How do we continue once a vertex belonging to the sink component has been discovered?  Recall: The strongly connected components can be linearized by arranging them in decreasing order of their post numbers.  Run DFS on G, keeping track of connected components  Process the vertices beginning and breaking ties using the decreasing order of their post numbers from step 1  Can neglect keeping pre and post numbers this time  Can neglect back-, cross-, and forward- edges this time as well

3 Questions  Is it correct?  Relies on the correctness of the properties we identified earlier  How long does it take?  2 DFS passes  O(||V|| + ||E||) – again!  Can we do better?

Assignment  HW #11:  Practice using the SCC-finding algorithm  Study for Midterm (Study Guide)  Testing Center: Tuesday-Thurs (10-12 July)  One page of notes hand written or typed by you  Read  Shortest Paths  Breadth First Search  Dijkstra’s Algorithm