- Source: Slowsort
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" (a parody of optimal algorithms and complexity analysis).
Algorithm
Slowsort is a recursive algorithm.
It sorts in-place.
It is a stable sort. (It does not change the order of equal-valued keys.)
This is an implementation in pseudocode:
Sort the first half, recursively. (1.1)
Sort the second half, recursively. (1.2)
Find the maximum of the whole array by comparing the results of 1.1 and 1.2, and place it at the end of the list. (1.3)
Sort the entire list (except for the maximum now at the end), recursively. (2)
An unoptimized implementation in Haskell (purely functional) may look as follows:
Complexity
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.