Bogosort

Bogosort is an esoteric sorting algorithm that has an average case of $$O(n \times n!)$$, and an unbounded worst case. It is unstable, and not adaptive.

= Explanation = To bogosort an array, check if the array is sorted. If it is sorted, terminate. Otherwise shuffle the array and repeat until the array is sorted.

= Example = take the array {2 5 1 6 2 3}.

Shuffle it.

{6 4 1 2 3 5}

Shuffle it.

{1 2 6 3 5 4}

approx. 12 mins later

{1 2 3 4 5 6}

Sorted!

= Pseudocode = procedure bogosort(array arr) do while not isSorted(arr) do shuffle(arr) end while end