Bogo Sort
Randomly shuffles the array, checks if it’s sorted, and repeats. The monkey with a typewriter approach.
0 elements
>Ready — Bogo Sort
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Analysis
BEST O(n)
AVG O((n+1)!)
WORST O(∞)
SPACE O(1)
Bogo Sort (a.k.a. Stupid Sort, Monkey Sort) works by randomly shuffling the entire array, then checking if it happens to be sorted. If not, shuffle again. Average case is O((n+1)!) which means for 10 elements you’d expect ~40 million shuffles. For 15 elements, heat death of the universe. Use small arrays unless you have a lot of patience.