next up previous
Next: Up: Previous:

Topological Sort

Application:
Scheduling
Let u represent event 1, and let v represent event 2
u must occur before v occurs

\psfig{figure=figures/f16-11.ps}

Problem:
Find a schedule for executing the events that preserves the ``before'' relation.
Solution:
Represent events as vertices and before(u,v) as a directed edge (u,v).

Let G = (V, E) be a directed, acyclic graph (DAG). If (u,v) $\in$ E, then u appears before v in the ordering of events in the schedule.



The vertices and edges in G are referred to as the topology of G.

We want to sort this topology based on some key such that u $\rightarrow$ v implies key(u) < key(v) (or key(v) < key(u) reverse sorted).

The finish times assigned by DFS satisfy this constraint.


next up previous
Next: Up: Previous: