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:
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:
The runtime
T(n)
T(n)=2T(n/2)+T(n-1)+1
A lower asymptotic bound for
T(n)
log2(n)/(2+\epsilon) | |
\Omega\left(n |
\right)
\epsilon>0
Slowsort is therefore not in polynomial time. Even the best case is worse than Bubble sort.