DAGs and Topological Order
Directed graphs without cycles
A Directed Acyclic Graph (DAG) (Definition 6.2.4, notes p. 92) is exactly what
it sounds like: a directed graph with no cycles. This single restriction gives
DAGs a remarkable property — they can be topologically sorted.
Topological sort: arrange the vertices in a linear order
such that every edge points
forward: if , then comes before in the ordering.
Why this is possible in every DAG: every DAG has at least one source (vertex
with ) and at least one sink (vertex with ).
This is provable by induction on the number of vertices (you can always strip off
a source, then argue on the smaller DAG).
Algorithm sketch (Kahn's algorithm):
1. Collect all sources (indegree 0) into a queue.
2. Output one source; delete its outgoing edges.
3. Any new source goes into the queue.
4. Repeat until all vertices are output.
DAGs are everywhere in symbolic AI:
- Task scheduling: a task depends on tasks that must
finish first. Encode as a DAG.
- Bayesian networks: variables are nodes; conditional dependencies are edges.
DAGs guarantee no circular causation.
- Causal inference: "X causes Y" is a directed edge; cycles would mean X causes
itself, which is ill-defined.
Definitions 6.1.6 (notes p. 85):
- Source: with (no predecessor).
- Sink: with (no successor).
- 0.0sTopological sort by source-peeling
- 1.5sSix nodes A through F and seven edges appear in cyan
- 3.5sAn order tracker on the right starts empty
- 4.5sRound 1: sources A and B turn green and join the order
- 6.0sRound 2: new sources C, D, and E turn green and join
- 8.0sRound 3: F alone completes the ordering
- 10.5sEvery DAG has a topological sort — a linear order consistent with edges