The ready heap picks the job
transcript
One packer. Many orders. Take the shortest first. Do not sort every time. Use a heap.
Four orders wait. Times four, three, one, two. The shortest is on top. Take it. The heap repairs itself. A new short order arrives. It rises to the top.
The heap holds only ready orders. An order that has not arrived stays out. It joins when its time comes. Never take a job that has not arrived.
Order zero starts at time one. It ends at time five. Three orders wait. The shortest goes next. The order is zero, two, three, one.
A heap push costs log n. A heap pop costs log n. A scan costs n each time. A hundred thousand orders: seventeen steps, not a hundred thousand.
Sorting all orders again costs n log n. A heap fixes only the top. That costs log n steps. Each new order costs the same.
A heap gives the best ready job. Each choice is quick. Try it in the sandbox. Full breakdown in the lecture.