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).

Algorithm

edit

Slowsort is a recursive algorithm.

A pseudocode implementation is given below:

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)
  • 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:

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

Complexity Analysis

edit

The time complexity of Slowsort is given by the function . It can be found by creating a recurrence relation of the initial recursive calls (1.1) and (1.2) respectively and summing the final recursive call (2) and modelling the other operations as a constant (+1) in this case. This gives a lower asymptotic bound for , which in Landau notation is given as for any . Therefore Slowsort is not in polynomial time.

References

edit
  1. ^ Andrei Broder; Jorge Stolfi (1984). "Pessimal Algorithms and Simplexity Analysis" (PDF). ACM SIGACT News. 16 (3): 49–53. CiteSeerX 10.1.1.116.9158. doi:10.1145/990534.990536. S2CID 6566140.

📚 Artikel Terkait di Wikipedia

Stooge sort

example of a fairly inefficient sort. It is, however, more efficient than Slowsort. The name comes from The Three Stooges. The algorithm is defined as follows:

Bogosort

wishes by picking a fast enough growing function f {\displaystyle f} . Slowsort A different humorous sorting algorithm that employs a misguided divide-and-conquer

Sorting algorithm

5 ) = O(n2.7095...) Can be made stable, and is also a sorting network. Slowsort o ( n log 2 ⁡ ( n ) / 2 ) {\displaystyle o\left(n^{\log _{2}(n)/2}\right)}

List of algorithms

Bogosort: the list is randomly shuffled until it happens to be sorted Slowsort Stooge sort Hybrid Flashsort Introsort: begin with quicksort and switch

Computer humour

technology meme referring to a confusing or inappropriate error message Slowsort, a humorous, not useful, sorting algorithm The Tao of Programming, a 1987