Sift Up
Compare with the parent and swap while the value outranks it. One path, O(log n).
Decision · step 3 of 6Binary Heap: Insert climbs to the root
1 is smaller than its parent 7, so they swap.
What you will see
The value climbs one level per swap until its parent is smaller (min heap).
Cost
| Best | O(1) |
|---|---|
| Average | O(log n) |
| Worst | O(log n) |
| Space | O(1) |
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, predict what happens next, try operations in any order.
Screen readers: Nodes announce value, parent and children; each step announces the comparison and whether the value moves up or down.
Reduced motion: Swaps become value crossfades in both the tree and the array view.
Before this
Related
Taught by the same lesson
Binary Heap covers these too, in the same run.