Bogosort

Bogosort
ClassSorting
Data structureArray
Worst-case performanceUnbounded (randomized version), (deterministic version)
Best-case performance[1]
Average performance[1]
Worst-case space complexity

In computer science, bogosort[1][2] (also known as permutation sort and stupid sort[3]) is a sorting algorithm based on the generate and test paradigm. The function successively generates permutations of its input until it finds one that is sorted. It is not considered useful for sorting, but may be used for educational purposes, to contrast it with more efficient algorithms.

Two versions of this algorithm exist: a deterministic version that enumerates all permutations until it hits a sorted one,[2][4] and a randomized version that randomly permutes its input. An analogy for the working of the latter version is to sort a deck of cards by throwing the deck into the air, picking the cards up at random, and repeating the process until the deck is sorted. In a worst-case scenario with this version, the random source is of low quality and happens to make the sorted permutation unboundedly unlikely to occur. The algorithm's name is a portmanteau of the words bogus and sort.[5]

  1. ^ a b c Cite error: The named reference Fun07 was invoked but never defined (see the help page).
  2. ^ a b Kiselyov, Oleg; Shan, Chung-chieh; Friedman, Daniel P.; Sabry, Amr (2005), "Backtracking, interleaving, and terminating monad transformers: (functional pearl)", Proceedings of the Tenth ACM SIGPLAN International Conference on Functional Programming (ICFP '05) (PDF), SIGPLAN Notices, pp. 192–203, doi:10.1145/1086365.1086390, S2CID 1435535, archived from the original (PDF) on 26 March 2012, retrieved 22 June 2011
  3. ^ E. S. Raymond. "bogo-sort". The New Hacker’s Dictionary. MIT Press, 1996.
  4. ^ Naish, Lee (1986), "Negation and quantifiers in NU-Prolog", Proceedings of the Third International Conference on Logic Programming, Lecture Notes in Computer Science, vol. 225, Springer-Verlag, pp. 624–634, doi:10.1007/3-540-16492-8_111, ISBN 978-3-540-16492-0.
  5. ^ "bogosort". xlinux.nist.gov. Retrieved 11 November 2020.