Slowsort is a sorting algorithm. It is of humorous nature and not useful. It is a reluctant algorithm based on the principle of multiply and surrender (a parody formed by taking the opposites of divide and conquer). It was published in 1984 by Andrei Broder and Jorge Stolfi in their paper "Pessimal Algorithms and Simplexity Analysis"[1] (a parody of optimal algorithms and complexity analysis).
Slowsort is a recursive algorithm.
This is an implementation in pseudocode:
procedure slowsort(A[], start_idx, end_idx) // Sort array range A[start ... end] in-place. if start_idx ≥ end_idx then return middle_idx := floor( (start_idx + end_idx)/2 ) slowsort(A, start_idx, middle_idx) // (1.1) slowsort(A, middle_idx + 1, end_idx) // (1.2) if A[end_idx] < A[middle_idx] then swap (A, end_idx, middle_idx) // (1.3) slowsort(A, start_idx, end_idx - 1) // (2)
An unoptimized implementation in Haskell (purely functional) may look as follows:
slowsort :: (Ord a) => [a] -> [a] slowsort xs | length xs <= 1 = xs | otherwise = slowsort xs' ++ [max llast rlast] -- (2) where m = length xs `div` 2 l = slowsort $ take m xs -- (1.1) r = slowsort $ drop m xs -- (1.2) llast = last l rlast = last r xs' = init l ++ min llast rlast : init r
The runtime T ( n ) {\displaystyle T(n)} for Slowsort is T ( n ) = 2 T ( n / 2 ) + T ( n − 1 ) + 1 {\displaystyle T(n)=2T(n/2)+T(n-1)+1} .
A lower asymptotic bound for T ( n ) {\displaystyle T(n)} in Landau notation is Ω ( n log 2 ( n ) / ( 2 + ϵ ) ) {\displaystyle \Omega \left(n^{\log _{2}(n)/(2+\epsilon )}\right)} for any ϵ > 0 {\displaystyle \epsilon >0} .
Slowsort is therefore not in polynomial time. Even the best case is worse than bubble sort.