Transcript
Building a bookshelf, some steps have to wait for others. The doors can't go on before the back and the shelves. So which order works, and how fast can the whole thing be done? Today: topological sorting.
Draw each step as a card, with an arrow from a step to anything that has to wait for it. Six steps, six arrows.
Start with every step that waits for nothing, here sides and feet, and put them in a queue from episode three. Take one out, do it, and cross off its arrows. Any step with nothing left to wait for joins the queue. Repeat until the queue is empty: sides, feet, back, shelves, doors, done. A valid order.
But add one bad rule: the sides need the doors first. Now the doors wait for the sides, and the sides wait for the doors. No step in that loop is ever free. The queue runs dry with steps left over, and that's how we know there's no possible order.
Now give each step its minutes. With a few helpers, steps that don't wait for each other can happen at the same time. The longest chain decides the total: sides, back, doors, done. Thirty-three minutes. That's the critical path: be one minute late on it, and everything is a minute late. The shelves have two minutes to spare.
Do what's free, cross off arrows, repeat, and keep an eye on the longest chain. That's how project plans and build tools choose an order. Next time: remember what you've already worked out, and some slow problems suddenly become fast. See you there.
Next episode: dynamic programming. Remember what you've already worked out, and slow problems suddenly become fast.