SortingAnimated
Bogosort
Shuffle until sorted. A joke algorithm that shows why efficiency matters.
Time
O(n · n!) expected
Extra space
O(1)
Use it for
Never.
How it works
- Check whether the list is sorted. If not, shuffle it randomly and check again.
- Repeat until it happens to be sorted.
- Expected shuffles ≈ n!: hopeless beyond a handful of items. It exists to show why a bad algorithm is bad.
- This demo uses a fixed random seed so it is repeatable, and stops after 60 shuffles.
Watch it run
Loading animation…