Module 5 · Heaps · Heap Tree Implementation

Heap operations

A min heap is a complete binary tree where every parent is smaller than its children, stored level by level in an array. Insert bubbles a value up, pop min sinks the replacement down — both O(log n) — while search has to look everywhere.

In the min heap every parent is smaller than its children. arr is the same heap, level by level: the children of i are at 2i+1 and 2i+2, its parent at (i−1)/2.

Operation

Time complexity

For a heap holding n values. Its height is about log₂ n, because every level is full before the next one starts. The highlighted row is the operation you are visualizing.