Here is a list of the strangest sorting algorithms and some of them are downright hilarious.
1 Sleep Sort
For every element x in an array, start a new program that:
- Sleeps for x seconds.
- Prints out x.
The clock starts on all the elements at the same time. It works for any array that has non-negative integers.
2 Quantum Bogosort
Quantum Bogosort is as follows:
- Randomly shuffle the elements of the list.
- If the list is not sorted, destroy the universe.
- Any surviving universes will then have the sorted version of the list.
Works in O(N) time. This algorithm relies on the accuracy of the many worlds theory of quantum mechanics.
3 Random Sort
It is as follows:
- Create and compile a random program.
- Run the random program on the input array.
- If the program produces sorted output, you are done.
- Else repeat from the beginning.
4 Solar Bitflip Sort
- Check if the array is sorted.
- If the array is sorted, return the array.
- If the array is not sorted, wait for 10 seconds and pray for having bit flips caused by solar radiation, just in the correct order then repeat from step 1.
5 Spaghetti Sort
- Convert the data to positive real values scaled to the length of a piece of spaghetti.
- Write each value onto a piece of spaghetti (a spaghetto) and break the spaghetti to the length equal to the scaled values.
- Hold all resulting spaghetti in a bundle and slam the end on a flat surface.
- Take the spaghetto which sticks out i.e. the longest one, read the value, convert back to the original value and write this down.
- Repeat until all spaghetti are processed.
Works in O(N) time.
6 Stalin Sort
- Gather up the comrades and show them the list.
- Ask the comrades to raise their hands if they believe the list is sorted.
- Select any comrade who did not raise his hand, and executes him as a traitor.
- Repeat steps 2 and 3 until everyone agrees that the list is sorted.
Usually, works in constant time.
- Randomly, shuffle the array.
- Check if it’s in order.
- If it’s not in order then reshuffle. Repeat until the array is in order.
8 Intelligent Design Sort
Whatever state your list is in, it’s already sorted meaning:
The probability of the original input list being in the exact order it’s in is 1/(n!). There is such a small likelihood of this that it’s clearly absurd to say that this happened by chance, so it must have been consciously put in that order my an intelligent sorted. Therefore it’s safe to assume that it’s already optimally sorted in some way that transcends our naive mortal understanding of ‘ascending order’. Any attempt io change that orders to conform to our own preconceptions would actually make it less sorted.
9 The Internet Sort
It’s just a bubble sort, but perform every comparison by searching the internet. For example, “Which is greater – 0.211 or 0.75?”.
10 Committee Sort
- To sort a list comprised of N natural numbers, start by printing out N copies of the whole list on paper.
- Now form N committees from any poor souls who happen to be milling around the office. The number of people on each committe should correspond to their particular value in the list.
- Each committee is given their sheet of paper and told to, through a meeting or some other means, decide where in the sorted list their number should fall.
- The list will be naturally sorted by the order that the committees return with their results.
And here’s a potato.