Some graphs specify an order in which things must be done; a common example is the course prerequisite structure of a university.

A * topological sort* orders the vertices
of a directed acyclic graph (DAG) so that if there is a path from vertex
*v _{i}* to

An easy way to find a topological sort is:

- initialize a queue to contain all vertices that have no
incoming arcs.
- While the queue is not empty,
- remove a vertex from the queue,
- put it into the sort order
- remove all of its arcs
- If the target of an arc now has zero incoming arcs, add the target to the queue.