Loading...
Linear ordering of DAG nodes respecting edge directions; basis for dependency resolution and DAG dynamic programming.
A topological order of a directed acyclic graph (DAG) arranges vertices linearly so every directed edge u→v places u before v. It exists iff the graph has no directed cycle.
Both Kahn and DFS traverse each vertex and edge once ignoring constant overheads.
Method | Mechanism | Cycle Signal | Stability |
---|---|---|---|
Kahn | Queue of in-degree 0 | Remaining vertices | Depends on queue order |
DFS | Reverse finish times | Back edge | Depends on DFS order |
Understand the degree decay process (Kahn) then animate queue evolution.