AlgoScope

Binary Heap

Data structureintermediateHeaps

A complete tree where every parent outranks its children, stored in a plain array.

Decision · step 3 of 12Binary Heap: Build a min heap
1489726current2 > 7

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

Open in the player →or start at step 3

What you will see

SIFT UP when a value is added, SIFT DOWN when the root leaves. One path either way.

How binary heap works →

Cost

insertO(log n)
extract topO(log n)
peekO(1)
buildO(n)
SpaceO(n)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.

Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.

Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.

Before this

Variants

  • Min Heap Smallest element at the root.
  • Max Heap Largest element at the root.

Taught by the same lesson

Binary Heap covers these too, in the same run.