**Topological sort**: arrange directed graph — one node per column — so that all edges point right.

If each node is a job to be scheduled, and each incoming edge indicates a prerequisite, a topological ordering is a valid job scheduling; sweeping left to right, all prerequisites have been satisfied.

My implementation is in git and below: