Originally published by Robert Beisert at fortcollinsprogram.robert-beisert.com

CS 101 – Algorithms: Bogosorts

A few fun algorithms, all of which are patently slow.

Bogosort – Theoretically, if we randomly shuffle the elements in our list, they will eventually be sorted.

while(LIST not sorted)

shuffle(LIST)

Bogobogosort – This is a slower bogosort, if you can believe it. Every time we fail to sort part of the list, we start over at the beginning!

while(LIST not sorted)

fetch(NEWLIST {element 1, element 2} )

while(NEWLIST not sorted)

Bogosort(NEWLIST)

if(NEWLIST is sorted)

addtolist(NEWLIST, next element)

else

goto Line 2 //fetch

Bozosort – Randomly swap two elements in the list until the list is sorted.

while(LIST not sorted)

swap(random, random)