Sort Target
Algorithm
Speed
Normal ~12s · 89 ms/step
Heapsort(1964)
▶ Try this Source
O(n log n) ✗ Stable ✓ In-place
🔧 How it works

Builds a max-heap from the array so the root always holds the largest unsorted value, then repeatedly extracts the root by swapping it with the last unsorted element, shrinks the heap boundary by one, and restores the heap property via sift-down.

🎯 Key property

In-place and O(n log n) in the worst case with no extra memory, but not stable and not adaptive, it performs the same amount of work on every input regardless of its existing order.

👁 Watch for
  • Compare during sift-down, the current node is compared against its two children; the larger child is promoted if it beats the parent
  • Swap the root swaps with the last unsorted element to extract the maximum; sift-down then swaps the demoted root downward until the heap property is restored
  • End of phase a heap-build phase first heapifies the entire array from the bottom up; the extraction phase then begins, growing the sorted region at the right one element per step
Initial State
This is the array before sorting. Follow Heapsort step by step.
Heap Tree
SORTED 5 3 8 1 9 2 7 4
0 / 135 ops ( 0.0%) 0.0%
Sorting is
a spectacle.
Algorithms at work, in a daily vertical feed. Watch, play, challenge — and go deeper when you're ready.
Loading 0%
An unhandled error has occurred. Reload 🗙