80 likes | 112 Views
Understand basic concepts, applications, and algorithms of topological sorting in directed acyclic graphs (DAGs). Learn about indegree/outdegree, ordering examples, and algorithm complexities.
E N D
Topological Sort Neil Tang03/02/2010 CS223 Advanced Data Structures and Algorithms
Class Overview • Basic concepts • An application • Algorithm 1 • Algorithm 2 CS223 Advanced Data Structures and Algorithms
Basic Concepts • A topological sort is an ordering of vertices in a DAG, such that if there is a path from vi to vj, then vj appears after vi in the ordering. • The topological sort may not be unique for a DAG. • Indegree/outdegree: the number of incoming/outgoing edges CS223 Advanced Data Structures and Algorithms
An Example Ordering 1: 1,2,5,4,3,7,6 Ordering 2: 1,2,5,4,7,3,6 CS223 Advanced Data Structures and Algorithms
An Application CS223 Advanced Data Structures and Algorithms
Topological Sort: Algorithm 1 Time complexity: O(|V|2) CS223 Advanced Data Structures and Algorithms
Topological Sort: Algorithm 2 Time complexity: O(|V|+|E|) CS223 Advanced Data Structures and Algorithms
Topological Sort: Algorithm 2 CS223 Advanced Data Structures and Algorithms