What is Heap Sort?
Heap Sort is an efficient sorting algorithm that uses a binary heap data structure. It builds a max heap, then repeatedly extracts the maximum element to build the sorted array.
The Basic Idea
Heap sort works by:
Why Heap Sort is Efficient
Heap sort combines the best features:
- Guaranteed O(n log n): Like merge sort
- In-place: Only O(1) extra space
- No worst case: Always O(n log n)
- No recursion: Can be implemented iteratively
Visual Example
Watch heap sort in action:
Heap Sort Visualization
1x
Key Characteristics
- Time complexity: O(n log n) in all cases
- Space complexity: O(1) - in-place sorting
- Stable: No - may change relative order
- Uses heap: Binary max heap data structure
Real-World Use
Heap sort is used when:
- You need guaranteed O(n log n) performance
- Memory is limited (in-place)
- You want to avoid worst-case scenarios
- Building priority queues
What’s Next?
Now that you know what heap sort is, let’s learn about binary heaps.
Progress 14%
Page 1 of 7
← Previous
→ Next