====== Chapter 3.6: Directed Acyclic Graphs & Topological Ordering ====== A directed graph with no cycles is called (obviously) a **directed acyclic graph** (DAG). DAGs can be used to encode //precedence relations// or //dependencies//. For example, if there are a set of tasks {1,2,...,n} that need to be performed and there are dependencies among them (i.e. for a pair //i// and //j//, //i// must be performed before //j//) then a DAG would be a way to represent those tasks. Each task can be a node, and there is a directed edge //(i,j)// whenever //i// must be done before //j//. If there is a cycle in the graph, there would be no way to do any of the tasks in that cycle since no task could ever be done first. A valid order for which the tasks could be performed with all of the dependencies respected is called a **topological ordering**. A topological ordering for a graph //G// is an ordering of its nodes as v_1, v_2,..., v_n so that for every edge //(v_i, v_j)// we have //i//