Sort Target
Algorithm
Speed
Normal ~12s · 154 ms/step
Circle sort(2016)
▶ Try this Source
O(n log² n) ✗ Stable ✓ In-place
🔧 How it works

Compares elements at the two ends of the current interval and swaps them if out of order, then moves both pointers inward until they meet, then recursively applies the same logic to each half. The outer loop repeats until a full pass produces no swaps.

🎯 Key property

Every comparison involves a pair of positions equidistant from the interval's centre, a mirror-image pattern that gives the algorithm its name. This symmetric structure allows multiple inversions to be resolved at once across the entire interval before diving into smaller sub-intervals, achieving O(n log² n) average performance.

👁 Watch for
  • Phase text "Circle [lo..hi] depth d" shows which interval is being processed and how deep in the recursion tree we are
  • Compare positions lo and hi are highlighted as a mirrored pair; both pointers converge toward the centre each step
  • Swap fires only when the outer pair is out of order, lo and hi exchange values, and the pointers advance inward
  • Recursion after the inward sweep completes, the algorithm dives into the left half then the right half at depth+1
  • End of pass the outer loop restarts only if at least one swap occurred during the entire recursive traversal; a swap-free pass means the array is sorted
Initial State
This is the array before sorting. Follow Circle sort step by step.
Main Array
5
0
3
1
8
2
1
3
9
4
2
5
7
6
4
7
0 / 78 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 🗙