"Learning how to learn is life's most important skill. " - Tony Buzan

Slides:



Advertisements
Similar presentations
CSE 2331/5331 CSE 780: Design and Analysis of Algorithms Lecture 14: Directed Graph BFS DFS Topological sort.
Advertisements

Chapter 9: Graphs Topological Sort
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Topological Sort and Hashing
Graph Algorithms: Topological Sort The topological sorting problem: given a directed, acyclic graph G = (V, E), find a linear ordering of the vertices.
Lecture 16: DFS, DAG, and Strongly Connected Components Shang-Hua Teng.
CSE 2331/5331 Topic 11: Basic Graph Alg. Representations Undirected graph Directed graph Topological sort.
Lecture 10 Topics Application of DFS Topological Sort
CSE 373: Data Structures and Algorithms Lecture 18: Graphs II 1.
1 Topological Sort Introduction. Definition of Topological Sort. Topological Sort is Not Unique. Topological Sort Algorithms. An Example. Implementation.
Topological Sort Introduction. Definition of Topological Sort. Topological Sort is Not Unique. Topological Sort Algorithm. An Example. Implementation.
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
Graphs.
© 2004 Goodrich, Tamasia Recall: Digraphs A digraph is a graph whose edges are all directed Short for “directed graph” Applications one-way streets flights.
Topological Sort: Definition
DIRECTED ACYCLIC GRAPHS AND TOPOLOGICAL SORT CS16: Introduction to Data Structures & Algorithms Tuesday, March 10,
CSC2100B Tutorial 10 Graph Jianye Hao.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 10 Prepared by İnanç TAHRALI.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
CSE 421 Algorithms Richard Anderson Autumn 2015 Lecture 5.
Week 11 - Wednesday.  What did we talk about last time?  Exam 2  And before that:  Graph representations  Depth first search.
© 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.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Graph Algorithms CS 202 – Fundamental Structures of Computer Science.
Directed Graphs 12/7/2017 7:15 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Topological Sorting.
CSC 172 DATA STRUCTURES.
Brief overview of topological sorting in graphs
CSE 2331/5331 Topic 9: Basic Graph Alg.
Topological Sort (an application of DFS)
CISC 235: Topic 10 Graph Algorithms.
Directed Graphs 9/20/2018 1:45 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Depth-First Search.
SINGLE-SOURCE SHORTEST PATHS IN DAGs
CS120 Graphs.
Directed Graphs Directed Graphs 1 Shortest Path Shortest Path
More Graph Algorithms.
Graph Search Applications
Topological Sort.
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill.
Topological Sort.
CSC 172 DATA STRUCTURES.
CS 3343: Analysis of Algorithms
Graph Algorithms – 2 DAGs Topological order
Advanced Algorithms Analysis and Design
CSE 373 Data Structures and Algorithms
Search Related Algorithms
Can you get there from here?
Topological Sort CSE 373 Data Structures Lecture 19.
Graph Representation (23.1/22.1)
Chapter 22: Elementary Graph Algorithms
Connected Components, Directed Graphs, Topological Sort
Graphs Part 2 Adjacency Matrix
CSE 373 Graphs 4: Topological Sort reading: Weiss Ch. 9
Richard Anderson Autumn 2016 Lecture 5
CSCI2100 Data Structures Tutorial
Lecture 16 CSE 331 Oct 8, 2012.
Lecture 16 CSE 331 Oct 2, 2013.
Topological Sort (an application of DFS)
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
Richard Anderson Winter 2009 Lecture 6
CSE 417: Algorithms and Computational Complexity
Backtracking.
CSE 373: Data Structures and Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 35 Graphs IV
Richard Anderson Lecture 5 Graph Theory
DAGs Longin Jan Latecki
Presentation transcript:

"Learning how to learn is life's most important skill. " - Tony Buzan Topological Sort "Learning how to learn is life's most important skill. " - Tony Buzan

Class Prerequisites Consider part-time student planning schedule Must take the following 10 required courses with the given prerequisites: Can take classes in any order, if prerequisite met. Can only take one class a semester. What order should the classes be taken? 142 143 321 322 326 341 370 378 401 421 none CS 321 - Data Structures

Graph Modelling Model problem as a directed, acyclic graph (DAG): nodes represent courses. contains an edge (u, v) if course u is a prerequisite of course v. Use topological sort to determine order to take classes. CS 321 - Data Structures

Topological Sort Topological sorting problem: Given directed acyclic graph (DAG) G = (V, E) , find a linear ordering of vertices such that for any edge (u, v) in E, u precedes v in the ordering may be more than one ordering Topological Sort CS 321 - Data Structures

Simple Topological Sort Algorithm Identify vertices with no incoming edges. The in-degree of these vertices is zero. If no vertices with no incoming edges, graph is not acyclic. doesn’t have a topological ordering. Remove one of these vertices and its edges from the graph. Return this vertex. Repeat until graph is empty. Order vertices are returned is topological ordering. CS 321 - Data Structures

Example: Simple Topological Sort 322 143 321 326 142 341 370 401 378 421 Identify vertices with no incoming edges. Only vertex with no incoming edges CS 321 - Data Structures

Example: Simple Topological Sort 322 143 321 326 341 370 401 378 421 Remove vertex and its edges. Output: 142 CS 321 - Data Structures

Example: Simple Topological Sort 322 143 321 326 341 370 401 378 421 Identify vertices with no incoming edges. Only vertex with no incoming edges Output: 142 CS 321 - Data Structures

Example: Simple Topological Sort 322 321 326 341 370 401 378 421 Remove vertex and its edges. Output: 142 143 CS 321 - Data Structures

Example: Simple Topological Sort 322 321 326 341 370 401 378 421 Identify vertices with no incoming edges. Four vertices with no incoming edges. Select one. Output: 142 143 CS 321 - Data Structures

Example: Simple Topological Sort 322 326 341 370 401 378 421 Remove vertex and its edges. Output: 142 143 321 CS 321 - Data Structures

Example: Simple Topological Sort 322 326 341 370 401 378 421 Identify vertices with no incoming edges. Five vertices with no incoming edges. Select one. Output: 142 143 321 CS 321 - Data Structures

Example: Simple Topological Sort 322 326 370 401 378 421 Remove vertex and its edges. Output: 142 143 321 341 CS 321 - Data Structures

Example: Simple Topological Sort 322 326 370 401 378 421 Identify vertices with no incoming edges. Four vertices with no incoming edges. Select one. Output: 142 143 321 341 CS 321 - Data Structures

Example: Simple Topological Sort 322 326 401 378 421 Remove vertex and its edges. Output: 142 143 321 341 370 CS 321 - Data Structures

Example: Simple Topological Sort 322 326 401 378 421 Identify vertices with no incoming edges. Three vertices with no incoming edges. Select one. Output: 142 143 321 341 370 CS 321 - Data Structures

Example: Simple Topological Sort 322 326 401 421 Remove vertex and its edges. Output: 142 143 321 341 370 378 CS 321 - Data Structures

Example: Simple Topological Sort 322 326 401 421 Identify vertices with no incoming edges. Two vertices with no incoming edges. Select one. Output: 142 143 321 341 370 378 CS 321 - Data Structures

Example: Simple Topological Sort Remove vertex and its edges. 326 401 421 Output: 142 143 321 341 370 378 322 CS 321 - Data Structures

Example: Simple Topological Sort Identify vertices with no incoming edges. 326 401 421 Only vertex with no incoming edge. Output: 142 143 321 341 370 378 322 CS 321 - Data Structures

Example: Simple Topological Sort Remove vertex and its edges. 401 421 Output: 142 143 321 341 370 378 322 326 CS 321 - Data Structures

Example: Simple Topological Sort Identify vertices with no incoming edges. 401 421 Two vertices with no incoming edges. Select one. Output: 142 143 321 341 370 378 322 326 CS 321 - Data Structures

Example: Simple Topological Sort Remove vertex and its edges. 401 Output: 142 143 321 341 370 378 322 326 421 CS 321 - Data Structures

Example: Simple Topological Sort Identify vertices with no incoming edges. Only vertex with no incoming edges. 401 Output: 142 143 321 341 370 378 322 326 421 CS 321 - Data Structures

Example: Simple Topological Sort Remove vertex and its edges. Output: 142 143 321 341 370 378 322 326 421 401 CS 321 - Data Structures

Example: Simple Topological Sort Therefore, the student can take the classes in this order: 142 143 321 341 370 378 322 326 421 401 There are many other possible orderings, depending how choose which vertex to remove if there’s more than one with no incoming edges. CS 321 - Data Structures

Analysis of Simple Topological Sort Runtime of each step: Initialize in-degree array: Find vertex with in-degree zero: 𝑉 vertices, takes 𝑂( 𝑉 ) to search in-degree array. Reduce degree of vertices adjacent to removed vertex: Output and mark removed vertex: Total time: CS 321 - Data Structures

Analysis of Simple Topological Sort Runtime of each step: Initialize in-degree array: Find vertex with in-degree zero: 𝑉 vertices, takes 𝑂( 𝑉 ) to search in-degree array. Reduce degree of vertices adjacent to removed vertex: Output and mark removed vertex: Total time: 𝑂( 𝐸 ) CS 321 - Data Structures

Analysis of Simple Topological Sort Runtime of each step: Initialize in-degree array: Find vertex with in-degree zero: 𝑉 vertices, takes 𝑂( 𝑉 ) to search in-degree array. Reduce degree of vertices adjacent to removed vertex: Output and mark removed vertex: Total time: 𝑂( 𝐸 ) 𝑂( 𝑉 2 ) CS 321 - Data Structures

Analysis of Simple Topological Sort Runtime of each step: Initialize in-degree array: Find vertex with in-degree zero: 𝑉 vertices, takes 𝑂( 𝑉 ) to search in-degree array. Reduce degree of vertices adjacent to removed vertex: Output and mark removed vertex: Total time: 𝑂( 𝐸 ) 𝑂( 𝑉 2 ) CS 321 - Data Structures

Analysis of Simple Topological Sort Runtime of each step: Initialize in-degree array: Find vertex with in-degree zero: 𝑉 vertices, takes 𝑂( 𝑉 ) to search in-degree array. Reduce degree of vertices adjacent to removed vertex: Output and mark removed vertex: Total time: 𝑂( 𝐸 ) 𝑂( 𝑉 2 ) 𝑂( 𝑉 ) CS 321 - Data Structures

Analysis of Simple Topological Sort Runtime of each step: Initialize in-degree array: Find vertex with in-degree zero: 𝑉 vertices, takes 𝑂( 𝑉 ) to search in-degree array. Reduce degree of vertices adjacent to removed vertex: Output and mark removed vertex: Total time: 𝑂( 𝐸 ) 𝑂( 𝑉 2 ) 𝑂( 𝑉 ) 𝑂( 𝑉 2 + 𝐸 ) CS 321 - Data Structures

Topological Sort with DFS The topological sort of a DAG G can by computed by leveraging the DFS algorithm CS 321 - Data Structures

Example: TS with DFS Modelling the order a person can dress: CS 321 - Data Structures

Example: TS with DFS The v.d and v.f times for the items after complete DFS. CS 321 - Data Structures

Example: TS with DFS Add items to list as finish each one. Topological Sort CS 321 - Data Structures

Analysis of Topological Sort with DFS Runtime of each step: DFS(G): Add vertex to front of list: Return list: Total time: CS 321 - Data Structures

Analysis of Topological Sort with DFS Runtime of each step: DFS(G): Add vertex to front of list: Return list: Total time: 𝑂( 𝑉 + 𝐸 ) CS 321 - Data Structures

Analysis of Topological Sort with DFS Runtime of each step: DFS(G): Add vertex to front of list: Return list: Total time: 𝑂( 𝑉 + 𝐸 ) 𝑂(1) CS 321 - Data Structures

Analysis of Topological Sort with DFS Runtime of each step: DFS(G): Add vertex to front of list: Return list: Total time: 𝑂( 𝑉 + 𝐸 ) 𝑂(1) CS 321 - Data Structures

Analysis of Topological Sort with DFS Runtime of each step: DFS(G): Add vertex to front of list: Return list: Total time: 𝑂( 𝑉 + 𝐸 ) 𝑂(1) CS 321 - Data Structures

CS 321 - Data Structures