Topological Sort definition
A topological sort orders the vertices of a directed graph so that every edge points from an earlier vertex to a later one.
Topological Sort in a picture
How it works
A directed graph admits such an ordering exactly when it has no directed cycle. One method repeatedly removes a vertex with no incoming edges in the remaining graph, placing it next in the order.
Worked examples
Give a valid order for A → B and B → C.
A, B, C.
Can A and B swap if they both only point to C?
Yes. A, B, C and B, A, C both work.
Can a directed cycle be sorted this way?
No. It would force a vertex to come before itself.
Common mistake
Use edge direction as precedence. A topological sort need not order vertices alphabetically or numerically.
Quick check
Must the order be unique?
Show answer
No.
What stops the zero-incoming-edge procedure before all vertices are placed?
Show answer
A directed cycle remains.
Sources
Flashcard
Topological Sort
Reveal the definition
A topological sort orders the vertices of a directed graph so that every edge points from an earlier vertex to a later one.
Effortless Math. “Topological Sort.” Math Dictionary.



