Always keep the largest (or smallest) element at the top, perfectly ready to grab.
A Heap is a special tree where the parent is always smaller than its children (Min-Heap) or larger (Max-Heap). It is complete, meaning it fills up level by level from left to right. Because of this perfect shape, we don't even need pointers—we can store the entire tree flat inside a simple Array!
When you insert, you put the item at the end of the array and "sift up" (swap with parent) until the rule is fixed. When you pop the root, you move the last element to the root and "sift down". Both take O(log n).
Because the tree is complete, the math is incredibly elegant (if using 0-indexing):
i: (i - 1) // 2i: 2 * i + 1i: 2 * i + 2