The best item, one step away
transcript
A hospital desk holds many patients. It must name the most urgent one. It must do that fast, every single time. It cannot sort everyone each time. A heap keeps the best on top. Watch a new patient arrive.
A new patient, urgency five, goes at the end. Compare with the parent, fifteen. Five is smaller, so swap up. Compare with the new parent, ten. Five is smaller, so swap up. Five is on top. Two swaps were enough.
The tree is complete, so it is short and wide. A push climbs one short path, level by level. It never visits the rest. The top is cell zero, one read.
A peek reads one cell. A push costs the height. A million items need about twenty levels. Sorting after each change would cost far more.
A heap keeps the order rule. The best item stays on top. Try a push in the sandbox. Full breakdown in the lecture.