A heap is a tree-shaped structure that keeps the smallest (or largest) element
instantly available. A min-heap guarantees that every parent is <= its children,
so the minimum is always at the root. (A max-heap flips the comparison.)
Heaps are usually a complete binary tree packed into an array — no pointers needed.
For the node at index i:
(i-1)/22*i + 12*i + 2The root (the min) sits at index 0.
Insert (sift-up): append the value at the end, then swap it upward while it's smaller than its parent — until the heap property holds again.
Extract-min (sift-down): the root is the answer; move the last element to the root, then swap it downward with its smaller child until it settles.
Both touch at most one root-to-leaf path, so they're O(log n). Peeking the min is O(1).
Go ships container/heap, but you'll hand-roll sift-up and sift-down here to see the
array index math up close. Once you have those two helpers, everything else is built on
top.