← Back to Arrays
Heap Sort Visualization
Heap Sort uses a binary heap data structure to sort elements. It first builds a max heap, then repeatedly extracts the maximum element and places it in the correct position.
Time Complexity
Best: O(n log n)
Average: O(n log n)
Worst: O(n log n)
Space
O(1)
Comparisons
0
Swaps
0
Phase
Ready
Array Visualization
Legend
Unsorted
Comparing
Swapping
Heap Root
Sorted
How Heap Sort Works
Phase 1: Build Max Heap
- • Start from the last non-leaf node
- • Apply heapify operation on each node
- • Ensure parent is larger than children
- • Continue until entire array forms max heap
Phase 2: Extract Maximum
- • Move root (maximum) to end of array
- • Reduce heap size by 1
- • Heapify the new root
- • Repeat until heap size is 1