Sift Up
Compare with the parent and swap while the value outranks it. One path, O(log n).
Binary Heap: Insert climbs to the root
1 is smaller than its parent 7, so they swap.
Cost
- Best
- O(1)
- Average
- O(log n)
- Worst
- O(log n)
- Space
- O(1)
Before this
Related
Leads to
Topics that need this one first.
Taught by the same lesson
Binary Heap covers these too, in the same run.