Worst | Average | Best |
---|---|---|
∞ | O(n×n!) | O(n) |
Worst | Average | Best |
---|---|---|
O(1) | O(1) | O(1) |
Good sorting algorithms are boring. Bogo Sort (also known as Stupid Sort) is a very inefficient sorting algorithm. It consists in repeatedly shuffling the array until (by sheer luck) it comes out sorted.
In the average case the algorithm needs to test all the n! permutations and for each one of them checking if the list is sorted requires O(n) time.
list = [...]
len = list.length
while not sorted(list):
shuffle(list)
(Source: Wikipedia)