Medium Heaps

Min-Heap

Rearranges an array of integers into min-heap order using Floyd's bottom-up build-heap algorithm: the array is read as a complete binary tree, where the value at index i has children at 2i + 1 and 2i + 2, and every parent must be less than or equal to both of its children. Starting from the last parent node and working back to the root, each subtree is sifted down — swapping a parent with its smallest child until the property holds or a leaf is reached. Returns a new array satisfying the min-heap property, the structure behind priority queues and efficient min/max retrieval.

Visualization

Input

Algorithm code

Custom input

Saved inputs

References