RosettaCodeData/Task/Sorting-algorithms-Bogosort/00DESCRIPTION

24 lines
802 B
Text
Raw Permalink Normal View History

2013-04-11 01:07:29 -07:00
{{Sorting Algorithm}}
2016-12-05 22:15:40 +01:00
;Task:
2015-02-20 00:35:01 -05:00
[[wp:Bogosort|Bogosort]] a list of numbers.
2016-12-05 22:15:40 +01:00
2015-02-20 00:35:01 -05:00
Bogosort simply shuffles a collection randomly until it is sorted.
2013-04-11 01:07:29 -07:00
2015-02-20 00:35:01 -05:00
"Bogosort" is a perversely inefficient algorithm only used as an in-joke.
2016-12-05 22:15:40 +01:00
Its average run-time is   O(n!)   because the chance that any given shuffle of a set will end up in sorted order is about one in   ''n''   factorial,   and the worst case is infinite since there's no guarantee that a random shuffling will ever produce a sorted sequence.
Its best case is   O(n)   since a single pass through the elements may suffice to order them.
2013-04-11 01:07:29 -07:00
Pseudocode:
'''while not''' InOrder(list) '''do'''
Shuffle(list)
'''done'''
2016-12-05 22:15:40 +01:00
<br>
2013-04-11 01:07:29 -07:00
The [[Knuth shuffle]] may be used to implement the shuffle part of this algorithm.
2016-12-05 22:15:40 +01:00
<br><br>