Orders the nodes of a directed acyclic graph (DAG) so every edge u → v goes from earlier to later in the order.
compute indegree[v] for all venqueue all v with indegree[v] = 0while queue not empty:u = dequeue(); output ufor each edge u → v: indegree[v]--; if indegree[v]=0 enqueue vif output has V nodes, return it; else cycle