Stooge sort

Stooge sort is an impractical sorting algorithm with a time complexity of $$O(n^{\log_{1.5}3}) \approx O(n^{2.71})$$. 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.

Quad stooge sort
Created by EilrahcF, this is defined as follows:


 * 1) Swap the first and last if they are out of order.
 * 2) Quad stooge the first two quarters of the array.
 * 3) Quad stooge the last two quarters of the array.
 * 4) Quad stooge the middle two quarters of the array.
 * 5) Quad stooge the last two quarters of the array (again).
 * 6) Quad stooge the first two quarters of the array.
 * 7) Quad stooge the middle two quarters of the array.

This variation reaches $$O(n^{\log_{2}6}) \approx O(n^{2.58})$$ time complexity for all cases. It is possible to re-arrange the recursion order so long as the recursion pattern mimics a valid sorting network of size four.

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 achieves a time complexity of $$O(3^n)$$. procedure hyper_stooge_sort(array arr, int i, int j) do compare and swap arr[i] and arr[j] if j - i > 1 then hyper_stooge_sort(arr, i, j-1) hyper_stooge_sort(arr, i+1, 1) hyper_stooge_sort(arr, i, j-1) end if end