Mental Model
We perform DFS on each node, first recursing on all its successors (nodes it points to, i.e., tasks that depend on it), then adding the node to the stack. Reversing the stack gives a topological order where for every edge u -> v, u comes before v.
Analogy: To assemble a toy car, you first recursively assemble all components that require the current part (like assembling the full car after wheels and body are ready, but in reverse: process dependents first). Finish order reversed ensures prerequisites first.
Graph: A -> B -> C ā D Topological order: D -> A -> B -> C (all arrows point forward)