There is a sort that's called bogobogosort. First, it checks the first 2 elements, and bogosorts them. Next it checks the first 3, bogosorts them, and so on.
Should the list be out of order at any time, it restarts by bogosorting the first 2 again. Regular bogosort has a average complexity of O(N!)
, this algorithm has a average complexity of O(N!1!2!3!...N!)
Edit: To give you an idea of how large this number is, for 20
elements, this algorithm takes an average of 3.930093*10^158
years,well above the proposed heat death of the universe(if it happens) of 10^100
years,
whereas merge sort takes around .0000004
seconds,
bubble sort .0000016
seconds,
and bogosort takes 308
years, 139
days, 19
hours, 35
minutes, 22.306
seconds, assuming a year is 365.242 days and a computer does 250,000,000 32 bit integer operations per second.
Edit2: This algorithm is not as slow as the "algorithm" miracle sort, which probably, like this sort, will get the computer sucked in the black hole before it successfully sorts 20 elemtnts, but if it did, I would estimate an average complexity of 2^(32(the number of bits in a 32 bit integer)*N)(the number of elements)*(a number <=10^40)
years,
since gravity speeds up the chips alpha moving, and there are 2^N states, which is 2^640*10^40
, or about 5.783*10^216.762162762
years, though if the list started out sorted, its complexity would only be O(N)
, faster than merge sort, which is only N log N even at the worst case.
Edit3: This algorithm is actually slower than miracle sort as the size gets very big, say 1000, since my algorithm would have a run time of 2.83*10^1175546
years, while the miracle sort algorithm would have a run time of 1.156*10^9657
years.