Data Structures, Explained Like You're Five: Heaps & Priority Queues
Imagine a family tree with one rule: every parent must be smaller than its children. Do that, and the very smallest value is always sitting at the top, ready to grab in an instant. That's a heap, and it's how a priority queue always knows what's most important right now.
The whole idea in one sentence
Keep a tree where every parent is smaller than its children (a "min-heap"), so the minimum is always the root — and when you add or remove, just let the new value bubble up or sink down until the rule holds again.
Watch it happen
Hit Play. Each new number drops in at the bottom and bubbles up past any bigger parent. Then watch extract-min pull the smallest off the top and re-settle the tree by sinking a value back down.
Why interviewers love it
A heap gives you the smallest (or largest) item in O(log n) every time, which makes it the engine behind priority queues — and priority queues are everywhere: Dijkstra's shortest path, task schedulers, "top K" problems, and heap sort. When a problem says "always handle the most urgent thing next," the answer is almost always a heap.
A heap isn't fully sorted — it just guarantees the top. That's the trick: you pay only O(log n) to keep the single most important item ready, instead of sorting everything.