Sorting algorithms/Bogosort: Difference between revisions

desc: stress on the random part
No edit summary
(desc: stress on the random part)
Line 1:
{{task|Sorting Algorithms}}{{Sorting Algorithm}}Bogosort a list of numbers. Bogosort simply shuffles a collection until it is sorted. (read the article on [[wp:Bogosort|Wikipedia]])
[[wp:Bogosort]] a list of numbers. Bogosort simply shuffles a collection randomly until it is sorted.
 
It is worth noting that "Bogosort" is a perversely inefficient algorithm and only used as an "in joke". Its typicalexpected run-time efficiency would be O(n!) ...because the chanceschance that any given shuffle of a set will end up in sorted order is about one in ''n'' factorial!, and the Worstworst case is infinite! since (Wethere's can neverno guarantee that a random shuffling will ever produce a sorted sequence).
 
Pseudocode:
Anonymous user