Mental Model
We find an order to do tasks so that all requirements come before the tasks that need them. We do this by always picking tasks that have no unmet requirements first.
Analogy: Imagine you have a list of homework assignments where some depend on others being done first. You start with assignments that have no prerequisites, finish them, then move on to assignments that become free of prerequisites as you go.
Graph: 0 -> 1 -> 3 ā ā 2 4 In-degree array: [0]=0, [1]=1, [2]=1, [3]=1, [4]=1 Queue initially: 0 (tasks with zero prerequisites)
