Curiosity cabinet · Beginner
Bogo Sort
Shuffle randomly until the sequence happens to be sorted.
- Best
- O(n)
- Average
- O(n × n!)
- Worst
- Unbounded
- Space
- O(1)
- Stability
- Not stable
- Memory model
- In-place
How it builds order
- Check whether the list is sorted.
- If not, shuffle uniformly.
- Check again.
- Eventually get lucky—with no useful worst-case bound.
Why it works
Every ordering is a possible shuffle; one of those n! permutations is sorted.
Watch for: The demo uses at most five items because expected work grows factorially.
The interactive version of this page adds the full trace, synchronized pseudocode, practice decisions, input experiments, and mastery review.