SortLab

Curiosity cabinet · Beginner

Sleep Sort

Schedule one timer per value and emit values as their timers wake.

Best
O(n) setup
Average
O(max value) wait
Worst
Scheduler-dependent
Space
O(n)
Stability
Not stable
Memory model
Uses auxiliary storage

How it builds order

  1. Create a timer for each nonnegative value.
  2. Use a delay proportional to that value.
  3. Emit values as callbacks wake.
  4. Observe scheduler and scaling limitations.

Why it works

If timers wake perfectly in delay order, smaller values emit first—an assumption real schedulers do not guarantee precisely.

Watch for: This is a concurrency demonstration, not a dependable comparison sort.

The interactive version of this page adds the full trace, synchronized pseudocode, practice decisions, input experiments, and mastery review.

Compare related strategies