Binary Heap
A complete tree where every parent outranks its children, stored in a plain array.
Decision · step 3 of 12Binary Heap: Build a min heap
Its left child 2 is smaller, so 7 sinks and 2 takes its place.
What you will see
SIFT UP when a value is added, SIFT DOWN when the root leaves. One path either way.
Cost
| insert | O(log n) |
|---|---|
| extract top | O(log n) |
| peek | O(1) |
| build | O(n) |
| Space | O(n) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.
Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.
Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.
Before this
Variants
- Min Heap Smallest element at the root.
- Max Heap Largest element at the root.
Leads to
Topics that need this one first.
Taught by the same lesson
Binary Heap covers these too, in the same run.