The idea
Key formulas
Array child indices
Array parent index
Loading lessons…
Just a moment, getting everything ready. The first load can take up to a minute.
Data structures and algorithms
Watch a min-heap insert by sifting up and extract its minimum by sifting down, in tree and array views.
A binary min-heap keeps each parent no larger than its children. Its complete-tree shape maps neatly to an array: children of index are and . Insertion appends then sifts up; extract-min moves the last value to the root and sifts down.
The root is always the minimum. Both operations take time in a binary heap.