All lessonsOpen Open Open Open Open
9. Heaps
Heap operations
0 of 5 activities0%
Reading 1
Restoring the heap property
Push: append, then sift up (swap with parent while heap property violated).
Pop max: move last to root, shrink, sift down.
Build heap: sift down from n/2-1 to 0 in O(n).
Check 2
Push cost
Heap push is
Fill in 3
Bubble
Try it 4
Sift up once
If child > parent, swap.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Is max-heap parent?
Read three ints: parent, left, right. Print yes if parent >= both children, else no.
main.cpp
Loading editor…