Workspace Topological Sort
0d
Problem-solving patterns

Topological Ordering

Repeatedly schedule a vertex whose remaining prerequisites are complete.

Recognition signal

Dependencies form directed edges, and all prerequisites must come first.

Method

Queue zero-indegree vertices and decrement successors as each is removed.

Worked example

With A → C and B → C, C becomes ready only after both A and B.

Common mistake

If fewer than V vertices are emitted, the remaining subgraph contains a directed cycle.