Build challenges · 4 steps · javascript · python

Binary Min-Heap

Construct an array-backed binary min-heap with parent/child arithmetic, siftUp, siftDown, and linear-time heapify.

A Binary Min-Heap is a complete binary tree where every parent node is smaller than or equal to its children.

Because the tree is always complete, we can store it directly in a flat array without pointer allocations:

In this build, you will construct a Binary Min-Heap from scratch:

  1. Implement constant-time root inspection (peek).
  2. Add elements with $O(\log n)$ upward bubbling (push and siftUp).
  3. Extract the minimum element with $O(\log n)$ downward bubbling (pop and siftDown).
  4. Transform an unsorted array into a valid min-heap in $O(n)$ linear time (heapify).

The workspace

These files carry across every step. What you write in one step is what you start the next with.

Steps · 0 of 4 done

  1. Root Inspection & Array Representation
  2. Insertion & Sift-Up
  3. Extract Minimum & Sift-Down
  4. Linear-Time Heapify

Start anywhere. Open step 3 first and you are handed the reference build of steps 1 and 2, so every step stands on its own. Nothing here is locked behind anything else.

This build applies Heaps & Priority Queues, Arrays & Traversal and Sorting. Read the lesson first if it is unfamiliar — a recommendation, not a prerequisite.

Shorter practice on the same ideas