All lessons

9. Heaps

Heap operations

0 of 5 activities0%

Reading 1

Restoring the heap property

Open

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

Open

Heap push is

Fill in 3

Bubble

Open

Moving a node upward to fix the heap is often called sift

Try it 4

Sift up once

Open

If child > parent, swap.

main.cpp
Loading editor…
Output will appear here.

Assignment 5

Is max-heap parent?

Open

Read three ints: parent, left, right. Print yes if parent >= both children, else no.

main.cpp
Loading editor…