Lecture 10 Topics Application of DFS Topological Sort

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Graph Algorithms
Advertisements

CSE 2331/5331 CSE 780: Design and Analysis of Algorithms Lecture 14: Directed Graph BFS DFS Topological sort.
Comp 122, Spring 2004 Graph Algorithms – 2. graphs Lin / Devi Comp 122, Fall 2004 Identification of Edges Edge type for edge (u, v) can be identified.
Tirgul 7 Review of graphs Graph algorithms: –DFS –Properties of DFS –Topological sort.
Elementary Graph Algorithms Depth-first search.Topological Sort. Strongly connected components. Chapter 22 CLRS.
Theory of Computing Lecture 6 MAS 714 Hartmut Klauck.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
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.
Graphs – Depth First Search ORD DFW SFO LAX
CSE 2331/5331 Topic 11: Basic Graph Alg. Representations Undirected graph Directed graph Topological sort.
Graphs II Kruse and Ryba Chapter 12. Undirected Graph Example: Subway Map.
CS 3343: Analysis of Algorithms Lecture 24: Graph searching, Topological sort.
Graphs - Definition G(V,E) - graph with vertex set V and edge set E
Tirgul 8 Graph algorithms: Strongly connected components.
Tirgul 11 DFS Properties of DFS Topological sort.
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.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Makeup Lecture Chapter 23: Graph Algorithms Depth-First SearchBreadth-First.
1 Data Structures DFS, Topological Sort Dana Shapira.
CSE 780 Algorithms Advanced Algorithms Graph Alg. DFS Topological sort.
Lecture 15: Depth First Search Shang-Hua Teng. Graphs G= (V,E) B E C F D A B E C F D A Directed Graph (digraph) –Degree: in/out Undirected Graph –Adjacency.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 14 Strongly connected components Definition and motivation Algorithm Chapter 22.5.
Depth-First Search Idea: Keep going forward as long as there are unseen nodes to be visited. Backtrack when stuck. v G G G G is completely traversed.
Topological Sorting and Least-cost Path Algorithms.
November 6, Algorithms and Data Structures Lecture XI Simonas Šaltenis Aalborg University
David Luebke 1 9/15/2015 CS 332: Algorithms Topological Sort Minimum Spanning Trees.
David Luebke 1 10/1/2015 CS 332: Algorithms Topological Sort Minimum Spanning Tree.
COSC 3101A - Design and Analysis of Algorithms 10
Elementary Graph Algorithms CSc 4520/6520 Fall 2013 Slides adapted from David Luebke, University of Virginia and David Plaisted, University of North Carolina.
Spring 2015 Lecture 10: Elementary Graph Algorithms
Graphs.
Graphs David Kauchak cs302 Spring DAGs Can represent dependency graphs underwear pants belt shirt tie jacket socks shoes watch.
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.
Elementary Graph Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
 2004 SDU Lectrue4-Properties of DFS Properties of DFS Classification of edges Topological sort.
Graph Algorithms.
CSC 201: Design and Analysis of Algorithms Lecture # 18 Graph Algorithms Mudasser Naseer 1 12/16/2015.
Chapter 22: Elementary Graph Algorithms
1 2/23/2016 ITCS 6114 Topological Sort Minimum Spanning Trees.
1 Chapter 22: Elementary Graph Algorithms III. 2 About this lecture Topological Sort.
1 Algorithms CSCI 235, Fall 2015 Lecture 35 Graphs IV.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
November 19, Algorithms and Data Structures Lecture XI Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
Chapter 22: Elementary Graph Algorithms Overview: Definition of a graph Representation of graphs adjacency list matrix Elementary search algorithms breadth-first.
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.
CS138A Elementary Graph Algorithms Peter Schröder.
Topological Sorting.
Chapter 22 Elementary Graph Algorithms
Undirected versus Directed Graphs
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.
CSE 2331/5331 Topic 9: Basic Graph Alg.
Topological Sort Minimum Spanning Tree
CSC 413/513: Intro to Algorithms
CS200: Algorithm Analysis
Many slides here are based on E. Demaine , D. Luebke slides
Graph Algorithms – 2 DAGs Topological order
Graph Representation Adjacency list representation of G = (V, E)
Graph Algorithms – 2.
Advanced Algorithms Analysis and Design
Analysis of Algorithms CS 477/677
Algorithms CSCI 235, Spring 2019 Lecture 35 Graphs IV
Chapter 22: Elementary Graph Algorithms III
Presentation transcript:

Lecture 10 Topics Application of DFS Topological Sort Strongly Connected Components Reference: Introduction to Algorithm by Cormen Chapter 23: Elementary Graph Algorithms Data Structure and Algorithm

Directed Acyclic Graph A directed acyclic graph or DAG is a directed graph with no directed cycles: Data Structure and Algorithm

DFS and DAG Theorem: a directed graph G is acyclic if and only if a DFS of G yields no back edges: => if G is acyclic, will be no back edges Trivial: a back edge implies a cycle <= if no back edges, G is acyclic Proof by contradiction: G has a cycle   a back edge Let v be the vertex on the cycle first discovered, and u be the predecessor of v on the cycle When v discovered, whole cycle is white Must visit everything reachable from v before returning from DFS-Visit() So path from u (gray)v (gray), thus (u, v) is a back edge v u Data Structure and Algorithm

Topological sort of a DAG: Linear ordering of all vertices in graph G such that vertex u comes before vertex v if edge (u, v)  G Real-world application: Scheduling a dependent graph, Find a feasible course plan for university studies Data Structure and Algorithm

Example Socks Undershorts Watch Shoes Pant Shirt Belt Tie Jacket Data Structure and Algorithm

Example (Cont.) Undershorts Watch Socks Jacket Tie Shirt Belt Shoes Pant Socks Jacket Undershorts Pant Shoes watch Shirt Belt Tie Data Structure and Algorithm

Algorithm 11/16 Undershorts Socks 17/18 Watch 12/15 Pant Shoes 13/14 9/10 Shirt 1/8 6/7 Belt Tie 2/5 Jacket 3/4 Socks Jacket Undershorts Pant Shoes watch Shirt Belt Tie 17/18 11/16 12/15 13/14 9/10 1/8 6/7 2/5 3/4 Data Structure and Algorithm

Algorithm Topological-Sort() { Call DFS to compute finish time f[v] for each vertex As each vertex is finished, insert it onto the front of a linked list Return the linked list of vertices } Time: O(V+E) Data Structure and Algorithm

Strongly Connected Components Every pair of vertices are reachable from each other Graph G is strongly connected if, for every u and v in V, there is some path from u to v and some path from v to u. Strongly Connected Not Strongly Connected Data Structure and Algorithm

Example { a , c , g } { f , d , e , b } a g c d e f b Data Structure and Algorithm

Finding Strongly Connected Components Input: A directed graph G = (V,E) Output: a partition of V into disjoint sets so that each set defines a strongly connected component of G Data Structure and Algorithm

Algorithm Strongly-Connected-Components(G) call DFS(G) to compute finishing times f[u] for each vertex u. Cost: O(E+V) compute GT Cost: O(E+V) call DFS(GT), but in the main loop of DFS, consider the vertices in order of decreasing f[u] Cost: O(E+V) output the vertices of each tree in the depth-first forest of step 3 as a separate strongly connected component. The graph GT is the transpose of G, which is visualized by reversing the arrows on the digraph. Cost: O(E+V) Data Structure and Algorithm

Example Data Structure and Algorithm