Stooge sort

Stooge sort is an impractical sorting algorithm with a time complexity of $$O(n^{\log_{1.5}3})$$. It is not stable and not adaptive. It also requires $$O(n)$$ stack memory.

Algorithm
The algorithm works as follows:


 * 1) Swap the first and last elements if they are out of order.
 * 2) Stoogesort the first two-thirds of the array (rounded up).
 * 3) Stoogesort the last two-thirds of the array.
 * 4) Stoogesort the first two-thirds of the array again.

Pseudocode
procedure stooge_sort(array arr,int i,int j) do if arr[j] < arr[i] do swap arr[i] and arr[j] end if if j - i + 1 > 2 do int s = floor((j - i + 1) / 3) stooge_sort(arr,i,j - s)        stooge_sort(arr,i + s,j) stooge_sort(arr,i,j - s)   end if end

Optimized Stooge sort
-

Stable Stooge sort
Fortunately, Stoogesort can be made stable: The first step of the algorithm can be modified to be only executed when the length of the list is only two.

Snuffle sort
Created by _fluffy, this is defined as follows:


 * 1) Swap the first and last elements if they are out of order.
 * 2) Repeat the following steps $$\lfloor\frac{n}{2}\rfloor$$ times, where $$n$$ is the length of the array:
 * 3) Snuffle sort the first $$\lfloor\frac{n + 1}{2}\rfloor$$ of the array.
 * 4) Snuffle sort the last $$\lceil\frac{n + 1}{2}\rceil$$ of the array.

Note the floor and ceiling functions: they only affect arrays of even lengths. The algorithm performs a much worse complexity of $$O(n^{\log n})$$ best, average, and worst case runtime.

Hyper Stooge sort
This is created by fungamer2. Instead of recursing using two-thirds of the array, it is modified to be $$n-1$$. It has a time complexity of $$O(3^n)$$.