COP 3530 Spring2012 Data Structures & Algorithms Discussion Session
Sort What is sort? Why sort? Examples – Dictionary – Search (Google)
Sorting Algorithms Quicksort Merge sort Heapsort Insertion sort Selection sort Shell sort Bubble sort Strand sort Smoothsort Tournament sort Cocktail sort Comb sort Gnome sort Bogosort Slowsort Cycle sort Topological sort
Directional Acyclic Graph (DAG) A set of vertices / directed edges Directional Acyclic
Directional Acyclic Graph (DAG) Why directional? – Relation between objects are asymmetric – E.g., parent to child, predecessor to successor
Directional Acyclic Graph (DAG) Why acyclic? – A collection of tasks – Ordered, s.t., certain tasks must be performed earlier than others T4 T5 T3 T2T1 T8 T6 T7 T1 T2 T3
Directional Acyclic Graph (DAG) Applications? – Program language processing (fundamental in CS) – Real-world traffic scheduling – Computer network traffic scheduling – So on
Topological Order Topological ordering of a directed acyclic graph is a linear ordering of its vertices such that, for every edge uv, u comes before v in the ordering u v
Topological Order Left to right first, then top to bottom 7, 5, 3, 11, 8, 2, 9, 10 smallest-numbered available vertex first 3, 5, 7, 8, 11, 2, 9, 10 fewest edges first 5, 7, 3, 8, 11, 10, 9, 2 largest-numbered available vertex first 7, 5, 11, 3, 10, 8, 9, 2
Topological Sort
Example
Time Complexity O(|N|+|E|)