WRITE · TRACE · UNDERSTAND

Topological Sort

Release tasks as their final prerequisite is removed

Your experiment

task_order(graph) returns any valid prerequisite-first order, or None for a cycle. graph maps every node to outgoing neighbours; every neighbour is a key.

Python runs in your browser. Your draft stays on this device.

What to look for

Indegree counts prerequisites that remain. Removing a ready task reduces the counts of its dependants. If no task is ready but some remain, a cycle blocks the schedule.

Watch your code work

Ready to experiment

Write a solution or load the worked answer, then choose Trace & check.

Step through arrays, variables and training curves produced by your own Python.