Bogo Sort Visualization
Bogo Sort shuffles the list at random and checks if it's sorted. Then it shuffles again.
How it works
Bogo Sort (also called permutation sort or stupid sort) checks whether the list is in order. If it isn't, it shuffles everything at random and checks again, forever if it has to.
On average it needs about n! shuffles. With 6 elements that's 720 tries, which is why the sim starts it at 6: you get to see it land. Push it past 8 and it switches to the endless version: with 13 elements it's billions of tries, and with hundreds it would not finish before the heat death of the universe.
What to watch for
At 6 elements, watch the shuffles blur until one lands in order and the sweep runs. Turn it up to hundreds and watch it never finish. That's the joke.
Complexity
- Best
- n
- Average
- n·n!
- Worst
- ∞
- Extra space
- 1
- Stable
- No
Race it
Same shuffle, same speed, one winner: Bogo vs Bubble. Or open the studio to try other layouts, sizes and speeds, and make a video of it.
FAQ
Will Bogo Sort ever finish?
With probability 1, eventually. In practice, for more than about a dozen elements, no.
What is the time complexity of Bogo Sort?
O(n · n!) on average and unbounded in the worst case.