Array:
1x
Heap / Priority Queue Visualizer

Build Heap — Floyd's Algorithm

Step 1 of 6

Given an unsorted array, Floyd's algorithm builds a valid heap in O(N) time — significantly better than inserting each element one-by-one which costs O(N log N).

Why O(N) and Not O(N log N)?

Floyd's insight: leaves don't need sifting. Starting from the last non-leaf and going up to root, each sift-down is bounded by the node's height, not the full tree height. The sum of all heights = O(N).

N × InsertO(N log N)each insert bubbles up full height
Floyd's siftDownO(N)most nodes are near leaves (short sifts)