Back to Academy
sorting
Heap Sort
Heap Sort builds a max-heap from the input array and then repeatedly extracts the maximum element from the heap, placing it at the end of the sorted portion of the array. It combines the efficiency of merge sort with the in-place advantage of insertion sort, guaranteeing O(n log n) performance without requiring extra memory.
Use Cases
- •When guaranteed O(n log n) worst-case is needed without extra memory
- •Priority queue implementations
- •Systems where consistent performance is more important than raw speed
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(n log n) | O(n log n) | O(n log n) |
| Space | O(1) | ||
Visualization
64
34
25
12
22
11
90
Implementation
Output
Click "Run Code" to see output...