More Graph Algorithms.

Slides:



Advertisements
Similar presentations
Chapter 9: Graphs Topological Sort
Advertisements

CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Topological Sort and Hashing
Minimum cost spanning tree and activity networks Data structure 2002/12/2.
Graph Algorithms: Topological Sort The topological sorting problem: given a directed, acyclic graph G = (V, E), find a linear ordering of the vertices.
§2 Topological Sort 〖 Example 〗 Courses needed for a computer science degree at a hypothetical university How shall we convert this list into a graph?
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
CS202 - Fundamental Structures of Computer Science II
Directed Graph Algorithms CSE 373 Data Structures Lecture 14.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Topological Sort Introduction. Definition of Topological Sort. Topological Sort is Not Unique. Topological Sort Algorithm. An Example. Implementation.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
CS 61B Data Structures and Programming Methodology Aug 5, 2008 David Sun.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Topological Sort: Definition
DIRECTED ACYCLIC GRAPHS AND TOPOLOGICAL SORT CS16: Introduction to Data Structures & Algorithms Tuesday, March 10,
DATA STRUCTURES AND ALGORITHMS Lecture Notes 10 Prepared by İnanç TAHRALI.
Graphs Upon completion you will be able to:
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Topological Sort. Sorting technique over DAGs (Directed Acyclic Graphs) It creates a linear sequence (ordering) for the nodes such that: –If u has an.
Graphs Spring 2016CS202 - Fundamental Structures of Computer Science II1 Initially prepared by Dr. Ilyas Cicekli; improved by various Bilkent CS202 instructors.
IOI/ACM ICPC Training 4 June 2005.
Topological Sorting.
Graphs Chapter 20.
CS202 - Fundamental Structures of Computer Science II
Chapter 22 Elementary Graph Algorithms
Unit 10 Graphs (1) King Fahd University of Petroleum & Minerals
CSE 373 Topological Sort Graph Traversals
CSC 172 DATA STRUCTURES.
CSE373: Data Structures & Algorithms Lecture 13: Topological Sort / Graph Traversals Kevin Quinn Fall 2015.
Cse 373 May 8th – Dijkstras.
CS202 - Fundamental Structures of Computer Science II
CISC 235: Topic 10 Graph Algorithms.
Introduction to Graphs
SINGLE-SOURCE SHORTEST PATHS IN DAGs
Topological Sort (topological order)
Graphs.
CS202 - Fundamental Structures of Computer Science II
CS120 Graphs.
Topological Sort.
Graph Algorithm.
Lecture 15 CSE 331 Sep 29, 2014.
Topological Sort.
CSC 172 DATA STRUCTURES.
Graphs Representation, BFS, DFS
"Learning how to learn is life's most important skill. " - Tony Buzan
Search Related Algorithms
Topological Sort CSE 373 Data Structures Lecture 19.
Directed Acyclic Graphs && Topological Sorting
Directed Graph Algorithms
Directed Graph Algorithms
CSE 373 Graphs 4: Topological Sort reading: Weiss Ch. 9
Richard Anderson Autumn 2016 Lecture 5
Lecture 16 CSE 331 Oct 8, 2012.
Lecture 16 CSE 331 Oct 2, 2013.
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
CSE 417: Algorithms and Computational Complexity
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Richard Anderson Winter 2019 Lecture 6
Lecture 11 Graph Algorithms
GRAPH – Definitions A graph G = (V, E) consists of
Assignment #2 (Assignment due: Nov. 06, 2018) v1 v2 v3 v4 v5
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Chapter 22: Elementary Graph Algorithms III
Presentation transcript:

More Graph Algorithms

Applications of Graphs: Topological Sorting Topological order A list of vertices in a directed graph without cycles such that vertex x precedes vertex y if there is a directed edge from x to y in the graph There may be several topological orders in a given graph Topological sorting Arranging the vertices into a topological order

Topological Sort Directed graph G. Rule: if there is an edge u  v, then u must come before v. Ex: A B G F C I H A B E D G F C I H E D

Intuition Cycles make topological sort impossible. Select any node with no in-edges print it delete it and delete all the edges leaving it Repeat What if there are some nodes left over? Implementation? Efficiency?

Implementation Start with a list of nodes with in-degree = 0 Select any edge from list mark as deleted mark all outgoing edges as deleted update in-degree of the destinations of those edges If any drops below zero, add to the list Running time?

Topological Sorting Figure 13.14 Figure 13.15 A directed graph without cycles Figure 13.15 The graph in Figure 13-14 arranged according to the topological orders a) a, g, d, b, e, c, f and b) a, b, g, d, e, f, c

Topological Sorting Simple algorithms for finding a topological order topSort1 Find a vertex that has no successor Remove from the graph that vertex and all edges that lead to it, and add the vertex to the beginning of a list of vertices Add each subsequent vertex that has no successor to the beginning of the list When the graph is empty, the list of vertices will be in topological order

Topological Sorting Simple algorithms for finding a topological order (Continued) topSort2 A modification of the iterative DFS algorithm Strategy Push all vertices that have no predecessor onto a stack Each time you pop a vertex from the stack, add it to the beginning of a list of vertices When the traversal ends, the list of vertices will be in topological order

Implementation Start with a list of nodes with in-degree = 0 Select any edge from list mark as deleted mark all outgoing edges as deleted update in-degree of the destinations of those edges If any drops below zero, add to the list Running time? In all, algorithm does work: O(|V|) to construct initial list Every edge marked “deleted” at most once: O(|E|) total Every node marked “deleted” at most once: O(|V|) total So linear time overall (in |E| and |V|)

Why should we care? Shortest path problem in directed, acyclic graph Called a DAG for short General problem: Given a DAG input G with weights on edges Find shortest paths from source A to every other vertex