Chapter 6Graphs and Treesnotes.en.pdf:92

DAGs and Topological Order

Directed graphs without cycles

Def 6.2.4DAGDef 6.1.6Source/Sink
Concept

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
vπ(1),vπ(2),,vπ(n)v_{\pi(1)}, v_{\pi(2)}, \dots, v_{\pi(n)} such that every edge points
forward: if (u,v)E(u, v) \in E, then uu comes before vv in the ordering.

Why this is possible in every DAG: every DAG has at least one source (vertex
with indeg=0\text{indeg} = 0) and at least one sink (vertex with outdeg=0\text{outdeg} = 0).
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 vv depends on tasks u1,,uku_1, \dots, u_k 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: vv with indeg(v)=0\text{indeg}(v) = 0 (no predecessor).
- Sink: vv with outdeg(v)=0\text{outdeg}(v) = 0 (no successor).

Animation — dags toposort
Transcript — click a line to jump7 cues
  1. 0.0sTopological sort by source-peeling
  2. 1.5sSix nodes A through F and seven edges appear in cyan
  3. 3.5sAn order tracker on the right starts empty
  4. 4.5sRound 1: sources A and B turn green and join the order
  5. 6.0sRound 2: new sources C, D, and E turn green and join
  6. 8.0sRound 3: F alone completes the ordering
  7. 10.5sEvery DAG has a topological sort — a linear order consistent with edges
Worked example
Step 0 of 2
Practice — score 100% to advance
Multiple choice
Q1
What is a DAG?
Q2
In a topological order of a DAG, every edge points…
Q3
A source vertex has…
Q4
Which is NOT a typical DAG application in AI?
Q5
Why does every non-empty DAG have a source?
Match definitions
Match each concept on the left to its definition on the right.
Order the steps
Arrange these proof steps in the correct order using the arrows.
1
Find all vertices with indeg(v)=0\text{indeg}(v) = 0 (sources)
2
Repeat until all vertices are placed
3
Pick any source, place it next in the order
4
Remove its outgoing edges from consideration
Loading…