Sometimes you need the lexicographically smallest topological order. Standard Kahn's algorithm uses a regular queue and picks nodes arbitrarily when multiple have in-degree .
To get the smallest order, replace the queue with a min-heap (priority queue). When multiple nodes have in-degree , the heap always gives you the smallest one first. This guarantees the lexicographically smallest valid topological ordering.
Example: Topological Sorting on SPOJ requires you to output the smallest valid permutation.