Heap Sort Visualizer
Binary heap construction, heapify, and extract operations
Ready. Generate an array and click Sort or Step.
How Heap Sort Works
Heap sort operates in two phases:
- Build Heap: Transform the array into a valid binary heap using bottom-up heapify. Each node is "sifted down" to maintain the heap property.
- Extract: Repeatedly swap the root (min or max) with the last unsorted element, shrink the heap boundary, and re-heapify the root.
Time complexity: O(n log n) in all cases. Space: O(1) auxiliary. Not stable.
Yellow = comparing,
Red = swapping,
Teal = sorted/extracted.