Sort Target
Algorithm
Speed
Normal ~12s · 83 ms/step
Tournament sort(1973)
▶ Try this Source
O(n log n) ✗ Stable ✗ In-place
🔧 How it works

Builds a complete binary winner tree where each leaf holds an element's span index and each internal node holds the index of the smaller of its two children. Repeatedly reads the global minimum from the root, swaps it to its final sorted position, retires the leaf with a sentinel, and replays only the two affected leaf-to-root paths to restore the tree.

🎯 Key property

Each extraction costs exactly log₂(n) comparisons, one per internal node on a single path, making it one of the most comparison-efficient selection-based algorithms, at the cost of O(n) auxiliary memory for the winner tree array.

👁 Watch for
  • Compare during replay, each node fires exactly one comparison between its two children to re-elect the winner; only two paths from leaves to root are ever touched per extraction, not the whole tree
  • Swap when the winner's leaf index differs from the sorted boundary, one swap moves the minimum to its final position; the displaced element's path is also replayed because the value at that position changed
  • CurrentMin the root always exposes the global minimum; watch it transfer to the sorted boundary and the tree immediately self-repair along the two changed leaf-to-root paths
Initial State
This is the array before sorting. Follow Tournament sort step by step.
Winner Tree
Step through to see the winner tree being built.
0 / 145 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 🗙