Binary Heap

Domain: Data Structures

šŸŽÆ Motivation

A heap implemented as a complete binary tree stored in an array. Parent at index i has children at 2i+1 and 2i+2.

šŸ“‹ Concrete Example

Array [10, 5, 3, 1, 2] represents a max-heap: index 0 (10) has children at index 1 (5) and 2 (3). No gaps in the tree.

šŸ”— Analogy

A fully packed stadium where every row is filled left to right before the next row starts. You know exactly where row i’s seats are without a map.