Topological Sort Neil Tang 03/02/2010 CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Class Overview Basic concepts An application Algorithm 1 Algorithm 2 CS223 Advanced Data Structures and Algorithms
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
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
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