AlgoScope

Heap Insert

Drop the value in the next free slot, then let it climb until its parent outranks it.

Heap algorithms, algorithm, intermediate
1 is added at index 6 as the next leaf, which keeps the tree complete.94821071current
1 is added at index 6 as the next leaf, which keeps the tree complete.94821071current

Binary Heap: Insert climbs to the root

Step, step 2 of 6

1 goes into the next free slot, index 6. That keeps the tree complete, but it is probably in the wrong place.

How binary heap works

Cost

Best
O(1)
Average
O(log n)
Worst
O(log n)
Space
O(1)

Leads to

Topics that need this one first.

Taught by the same lesson

Binary Heap covers these too, in the same run.