80 likes | 109 Views
Topological Sort Neil Tang 03/02/2010. Class Overview. Basic concepts An application Algorithm 1 Algorithm 2. Basic Concepts. A topological sort is an ordering of vertices in a DAG , such that if there is a path from v i to v j , then v j appears after v i in the ordering.
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