How to use the visualizer

1. Choose min or max

The kind decides which way comparisons go: a min-heap keeps the smallest value at the root, a max-heap the largest. Switching kinds starts a fresh session.

2. Build the heap

Either insert numbers one at a time (each insert appends at the next free slot and sifts up), or type a list — the sample from class is pre-filled — and press Heapify to watch the build-from-below: every parent sifted down, last parent first. Up to 15 whole numbers keep the tree readable.

3. Operate and replay

Extract removes the root: it swaps with the last element, the heap shrinks, and the new root sifts down — the extracted value stays parked in the array, greyed out. Heap sort repeats that until the array is sorted in place. Every operation plays automatically; use the controls to pause, change speed, step one compare-or-swap at a time, or scrub backwards through the whole session — nothing is ever lost until you clear or switch kinds.

Reading the two views

  • The tree is the mental model: node i's children are 2i+1 and 2i+2.
  • The array is the reality: one flat list, no pointers. Both views highlight the same compares and swaps.
  • Dashed array cells sit beyond len — extracted values in place, forming heap sort's output.
  • Your numbers never leave the browser — see About & privacy.