Directed Acyclic Graph (DAG)
Context: FIT2004_MOC Β· directed no cycle β the graph class on which β before β is globally consistent, so it can be sorted
Quick Revision
- π― Objective: an edge asserts a one-way dependency β acyclicity is what makes the dependencies simultaneously satisfiable.
- β οΈ Key Constraint: acyclicity is the whole content β the instant one cycle exists, no topological order exists and the model is unsatisfiable.
π Core
- Definition β a directed Graph containing no directed cycle; edges are ordered pairs , so .
- What one edge means β four readings of the same fact: is a prerequisite of Β· is an ancestor of Β· is a subset of Β· is ordered before . The last is what licenses Topological Sort.
- Models it fits β unit prerequisite chains (FIT1045 β FIT1008 β FIT2004) Β· project-management task dependencies Β· skill/talent trees Β· the DAG built to solve longest common subsequence.
- Models it does not β anything mutually dependent:
JOB β EXPERIENCEis a -cycle, so no order satisfies both edges β this is the examβs canonical non-DAG. - A Tree is a DAG β acyclic, with the root the unique vertex having no incoming edge; a DAG generalises it by allowing a vertex several parents.
- Detecting it β run Topological Sort: a run that cannot place all vertices is a cycle certificate, at β the same cost as confirming the DAG.
- Detecting it directly β a three-state DFS (unvisited / active / inactive) also decides it in ; a DAG is exactly a digraph with no back edge β no edge into a vertex still on the current search path.
β οΈ Common Mistakes
- π‘ βDirected and no undirected cycleβ β only directed cycles are forbidden. , , , has an undirected cycle and is still a perfectly good DAG.
- π‘ Assuming a unique root β a DAG may have many sources (in-degree ) and many sinks (out-degree ); only a Tree is promised one root.
π§ Active Recall
Why is acyclicity the precondition for ordering, rather than just a tidy property?
Answer
- Short answer: a cycle asserts and at once, so no permutation can satisfy every edge.
- Why: The edge relation must be a strict partial order β means precedes , and a directed cycle makes that relation non-antisymmetric. Hence βis it a DAGβ and βdoes a Topological Sort existβ are the same question β one algorithm answers both in .
Give a real dependency that is not a DAG, and say what modelling move repairs it.
Answer
- Short answer: βneed a job to get experience, need experience to get a jobβ β a -cycle; split the vertices over time to break it.
- Why: Cycles usually signal a missing time index β is acyclic. The same trick underlies DP-on-a-DAG β indexing subproblems by size makes the dependency graph acyclic, which is why LCS becomes a DAG problem.