Rebalance two heaps with one move
transcript
A new score arrives. One half may get too big. One move fixes it. Watch.
Compare the score with the lower top. At most the lower top? It joins the lower half. Otherwise it joins the upper half. That keeps the order rule.
Eight is the first score. It joins the lower half. Three is at most eight, so it joins too. The lower half has two, the upper none. That is too many. Pop the top, eight. Push eight into the upper half. The halves are even.
Two more than the upper half is too big. Pop the lower top, and push it up. The upper half bigger than the lower is too big. Pop the upper top, and push it down.
An add changes a size by one. So a single move across is enough. Skip it, and the tops are wrong. Do it after every add.
Choose a side by the lower top. Move one top across if needed. Full breakdown in the lecture.