Heap Sort
Build a max-heap in place, then repeatedly swap the root to the end of the shrinking heap and sift the new root down.
Decision · step 2 of 26Heap Sort: Eight values
Index 3 holds 5; its larger child is 2 at index 7. 5 is already at least as large, so the heap property holds here.
What you will see
Heap view and array view together; the root swaps to the end and the heap shrinks by one.
Cost
| Best | O(n log n) |
|---|---|
| Average | O(n log n) |
| Worst | O(n log n) |
| Space | O(1) |
Properties
- ✓ comparison based
- × stable
- ✓ in place
- × adaptive
- × online
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, compare two runs.
Screen readers: Cells announce index, value and state (comparing, swapped, sorted); each step announces the comparison outcome and any move.
Reduced motion: Swaps become value crossfades with outline flashes; sorted-region growth is a static span change.