Heap Sort Visualizer
Watch Heap Sort build a max heap and extract values into sorted order with animated operations, playback controls, and metrics.
Comma-separated numbers, up to 20 values.
Live operation
compare
Live binary heap
Comparisons
1
Moves / writes
0
Confirmed sorted
0 / 10
Algorithm notes
What to watch for
Heap Sort uses the array as a complete binary tree. Heapify establishes the max-heap rule; each extraction moves the current maximum to the sorted suffix.
Concept guide
Review the mental model, tradeoffs, and practical use cases after you experiment.
Heap Sort Complete Info Card
Heap Sort is an efficient sorting algorithm that uses a binary heap data structure. It first builds a max heap from the input data, then repeatedly extracts the maximum element to produce a sorted array.
Algorithm Characteristics
Time Complexity (Best)
Same as average case
Time Complexity (Average)
Consistent performance
Time Complexity (Worst)
Guaranteed performance
Space Complexity
In-place sorting algorithm
Stable
May change order of equal elements
Comparison Sort
Compares elements to determine order
Sorting Process Steps
Build a max heap from input array
Swap root (max) with last element
Reduce heap size by one
Heapify the new root
Repeat until heap size is 1
Heap Operations
Heapify
Build Heap
Extract Max
Comparison with Other O(n log n) Sorts
| Algorithm | Time | Space | Stable |
|---|---|---|---|
| Quick Sort | O(n log n) avg | O(log n) | No |
| Merge Sort | O(n log n) | O(n) | Yes |
| Heap Sort | O(n log n) | O(1) | No |
Advantages
- •Guaranteed O(n log n) performance
- •Memory efficient (in-place)
- •No recursion (avoids stack overflow)
Limitations
- •Not stable (equal elements may be reordered)
- •Poor cache performance compared to Quick Sort
- •Slower in practice than Quick Sort for arrays