AlgoScope

Max Heap

A binary heap whose root is the largest value.

Data structures, data structure, intermediate
Comparing 2 with its children. The left child 7 is larger, so the two swap.895327current2 < 7
Comparing 2 with its children. The left child 7 is larger, so the two swap.895327current2 < 7

Binary Heap: Build a max heap

Decision, step 3 of 11

Its left child 7 is larger, so 2 sinks and 7 takes its place.

How binary heap works

Cost

Insert
O(log n)
Extract max
O(log n)
Peek
O(1)
Space
O(n)

A variant of

Taught by the same lesson

Binary Heap covers these too, in the same run.