Sift-up swaps in a binary heap
A min-heap is stored as the array [1, 3, 2, 7, 8, 5, 9] (index is the root; the children of index are at and ). You insert the value 0 at the next free slot (index ) and sift it up to restore the heap. How many swaps does the sift-up perform?
Show hints (2)+
- Parent of index is ; swap while child parent.
- Trace the path .
Answer
Reveal answer →Final answer
3
Create a free account to see the full worked solution and track your progress.
Interview format: Hedge Fund Quant, Prop Trading