Unit content
Topological ordering of directed acyclic graphs
A topological ordering of a directed acyclic graph places its vertices in a sequence such that every directed edge
$$u\to v$$
places $u$ before $v$.
Such an ordering exists exactly when the directed graph has no directed cycle.
One algorithm repeatedly removes a vertex with indegree zero and then removes its outgoing edges. Another uses depth-first search and orders vertices by decreasing finish time.
With adjacency lists, either approach can run in
$$O(|V|+|E|)$$
time.
A topological order is not necessarily unique. It represents one valid linear schedule consistent with a partial set of dependencies, making it useful for build systems, prerequisite graphs and task scheduling.