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

Maintains a forest of Leonardo heaps, whose sizes follow the Leonardo number series 1, 1, 3, 5, 9, 15, 25, …, adding each element to extend the rightmost heap, then extracts elements by dismantling the forest in reverse order.

🎯 Key property

Adaptive, when the input is already sorted no swaps are performed and the algorithm completes in O(n); unlike standard Heapsort it degrades gracefully rather than always running in full O(n log n) regardless of input order.

👁 Watch for
  • Compare during the build phase, adjacent heap roots are compared to keep them in order; during sift-down within a heap, each node is compared against its two children
  • Swap when a heap root is smaller than the previous heap's root, the roots swap and sift-down propagates the change downward to restore the local heap property
  • End of phase the extraction phase removes elements from the rightmost Leonardo heap, splitting it into two smaller Leonardo heaps that are relinked into the remaining forest
Initial State
This is the array before sorting. Follow Smoothsort step by step.
Main Array
5
0
3
1
8
2
1
3
9
4
2
5
7
6
4
7
0 / 95 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 🗙