Data Structures Using C++ 2E1 Topic of this lecture: Topological Order OU CS prerequisite bubble chart

Slides:



Advertisements
Similar presentations
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Advertisements

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.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Topological Sort.
Data Structures Using C++
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.
GRAPHS Lecture 18 CS2110 – Fall Graph Algorithms 2 Search –depth-first search –breadth-first search Shortest paths –Dijkstra's algorithm Minimum.
Algorithms and Data Structures
Graphs. 2 Some Examples and Terminology A graph is a set of vertices (nodes) and a set of edges (arcs) such that each edge is associated with exactly.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Lecture 16: Tree Traversal.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Data Structures Using C++
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Data Structures Using Java1 Chapter 11 Graphs. Data Structures Using Java2 Chapter Objectives Learn about graphs Become familiar with the basic terminology.
Advanced Data Structures
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
James Tam Introduction To Graphs In this section of notes you will learn about a new ADT: graphs.
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Tyler Robison Summer
CSE332: Data Abstractions Lecture 16: Topological Sort / Graph Traversals Dan Grossman Spring 2010.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graph Traversals Depth-First Traversal. The Algorithm.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
CS 206 Introduction to Computer Science II 11 / 03 / 2008 Instructor: Michael Eckmann.
CSE 373: Data Structures and Algorithms Lecture 18: Graphs II 1.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Graphs & Graph Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 28 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
CSC 2300 Data Structures & Algorithms March 30, 2007 Chapter 9. Graph Algorithms.
Data Structures Using C++ 2E
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Recursion Bryce Boe 2013/11/18 CS24, Fall Outline Wednesday Recap Lab 7 Iterative Solution Recursion Binary Tree Traversals Lab 7 Recursive Solution.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
2013-T2 Lecture 22 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and Thomas.
Common final examinations When: Wednesday, 12/11, 3:30-5:30 PM Where: Ritter Hall - Walk Auditorium 131 CIS 1166 final When: Wednesday, 12/11, 5:45-7:45.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
COSC 2007 Data Structures II
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
DIRECTED ACYCLIC GRAPHS AND TOPOLOGICAL SORT CS16: Introduction to Data Structures & Algorithms Tuesday, March 10,
More Binary Search Trees, Project 2 Bryce Boe 2013/08/06 CS24, Summer 2013 C.
Graphs Chapter 28 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Lecture 9: Graphs & Graph Models. Definition of a Graph edge vertex cycle path.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
CSE373: Data Structures & Algorithms Lecture 14: Topological Sort / Graph Traversals Dan Grossman Fall 2013.
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.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
CSE 373 Topological Sort Graph Traversals
CSE373: Data Structures & Algorithms Lecture 13: Topological Sort / Graph Traversals Kevin Quinn Fall 2015.
CS120 Graphs.
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
More Graph Algorithms.
"Learning how to learn is life's most important skill. " - Tony Buzan
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Graph Algorithms "A charlatan makes obscure what is clear; a thinker makes clear what is obscure. " - Hugh Kingsmill CLRS, Sections 22.2 – 22.4.
Graph Traversal Lecture 18 CS 2110 — Spring 2019.
CSE 417: Algorithms and Computational Complexity
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Lecture 11 Graph Algorithms
Presentation transcript:

Data Structures Using C++ 2E1 Topic of this lecture: Topological Order OU CS prerequisite bubble chart upload/CS-BUBBLE-CHART-October-2012.pdf

Data Structures Using C++ 2E

topologicalOrder[n-1]

Data Structures Using C++ 2E5 Topological Order Algorithm topological order –Outputs directed graph vertices in topological order –Assume graph has no cycles There exists a vertex v in G such that v has no successor There exists a vertex u in G such that u has no predecessor

Data Structures Using C++ 2E6 Topological Order (cont’d.) Topological sort algorithm –Implemented with the depth first traversal or the breadth first traversal Depth-first (stack) vs. Breadth-first (queue) Depth-first: CS 2400  2401  3610  4040  …  EE1024… Breadth-first: CS 2400  EE1024  Chem 1510  Math 2301  CS 2401 …

Data Structures Using C++ 2E7 Breadth First Topological Ordering General algorithm: 1.Use an array predCount to record the number of predecessors (prerequisites) for each node (course) 2.For a node (course) without any predecessor (prerequisite), it can be output (taken) 3.Use a queue for breadth-first traversal (maintain the prerequisite-cleared courses).

8 How to initialize preCount?

9 How to do breadth-first traversal?

Data Structures Using C++ 2E10 How to do Breadth First Topological Ordering? Similar to breadth-first traversal: using a queue, but only put prerequisite-cleared items ( predCount == 0) into the queue. When an item is removed from the queue, update the predCount values for the successors predCount[CS3610] = 2 After taking CS 2400, it should be reduced by 1. After taking CS 3000, it will be become 0.

Data Structures Using C++ 2E Breadth First Topological Ordering

Data Structures Using C++ 2E12 Breadth First Topological Ordering (cont’d.) Breadth First Topological order – FIGURE Arrays predCount, topologicalOrder, and queue after Steps 1 and 2 execute

Data Structures Using C++ 2E13 Breadth First Topological Ordering (cont’d.) Breadth First Topological order – FIGURE Arrays predCount, topologicalOrder, and queue after the first iteration of Step 3

Data Structures Using C++ 2E14 FIGURE Arrays predCount, topologicalOrder, and queue after the second iteration of Step 3

Data Structures Using C++ 2E15 FIGURE Arrays predCount, topologicalOrder, and queue after the third iteration of Step 3

Data Structures Using C++ 2E16 Breadth First Topological Ordering (cont’d.) See code on pages –Function implementing breadth first topological ordering algorithm FIGURE Arrays predCount, topologicalOrder, and queue after Step 3 executes

Data Structures Using C++ 2E17 How to do Depth First Topological Ordering? Project 5 question. Use depth-first traversal with recursive calls. Find a course without successor (e.g, CS 4561) through depth-first traversal and assign it into topologicalOrder[n- 1]. When you trace back, assign topologicalOrder[n-2], [n-3]…..

Data Structures Using C++ 2E18 How to do Depth First Topological Ordering? A course should NOT be output (taken) until the subtrees have been visited. Decrement topIndex each time when you output a course. Assign topologicalOrder[topIndex--] at the end of recursive calls. Pre-requisites are guaranteed to be taken first.

Data Structures Using C++ 2E19 Depth First Topological Ordering If start at 0, dft to 10, then 10 will be put as the last element in toplogicalOrder[]; 8 will be the second last. Output: