Heaps & Live Charts
In short: a heap is a binary tree with two rules. Shape: it's
complete — every level is full except perhaps the last, which fills from
the left, so it needs no pointers at all: just a plain list, with
parent(i) = (i-1)//2, left(i) = 2i+1, right(i) = 2i+2. Order: in a
min-heap, every parent is ≤ its children, so the smallest item always sits
at index 0 — a far weaker promise than "sorted", and much cheaper to keep.
Pushing sifts the new item up while it beats its parent; popping moves
the last item to the root and sifts it down while a child beats it. Each
move travels one level at a time, so both cost O(log n).

Keep the live chart's leader always one step away
Tunebox's live chart shows the most-played tracks right now, and plays arrive by the thousand every minute. Re-sorting after every play costs O(n log n) each time; a heap absorbs each change in O(log n). Because the shape has no gaps, parent and child links become arithmetic on a list:
The heap is just this list, and every parent and child link is an index calculation on it.
Index 0 is the root, so the smallest value always sits at the front of the list. 6 cells. At index 0.
The same six values drawn as a complete tree, filled level by level from the left with no gaps.
The root is index 0, and it beats both of its children, 8 and 5. Binary tree, 6 nodes, height 3. At node 3.
heap = [3, 8, 5, 12, 9, 7]
i = 2
print(heap[(i - 1) // 2], heap[2 * i + 1])❓ Cross-question — "So a heap is just a sorted list?" No, and that's the point.
[3, 8, 5, 12, 9, 7]isn't sorted — 8 comes before 5. A heap only promises each parent beats its own children; that weaker promise is much cheaper to keep, and it still puts the winner at index 0.