Bogosort

From Wikipedia, the free encyclopedia

Bogosort is a particularly ineffective sorting algorithm. Its only use is for educational purposes, to contrast it with other more realistic algorithms. Used to sort a deck of cards, it would consist of throwing the deck in the air, picking the cards up at random, and testing for order. If they are not in order, repeat. It is named after the humorous term quantum bogodynamics and, ultimately, the word bogus. Other names are stupid sort, bozo sort, blort sort, monkey sort, random sort and drunk man sort.


Contents

[edit] Running time and termination

This sorting algorithm is probabilistic in nature. If all elements to be sorted are distinct, the expected complexity is O(n × n!). The exact expected running time depends on how many different element values occur, and how often each of them occurs, but for non-trivial cases the expected running time is super-exponential in n since n! outgrows an. It terminates for the same reason that the infinite monkey theorem holds; there is some probability of getting the right permutation, so given an unbounded number of tries it must eventually find it.


[edit] Related algorithms

[edit] Bozo sort

Bozo sort is another sorting algorithm based on random numbers. If the list is not in order, it picks two items at random and swaps them, then checks to see if the list is sorted. It also faces the same pseudo-random problems as bogosort—it may never terminate.

[edit] Quantum Bogosort

An in-joke among some computer scientists is that quantum computing could be used to effectively implement a bogosort with a time complexity of O(n). It uses true quantum randomness to randomly permute the list. By the many-worlds interpretation of quantum physics, the quantum randomization spawns an infinite array of universes and some of these will be such that the single shuffle had produced the list in sorted order because the total number of distinct orderings, though large, is not infinite. The list is then tested for sortedness (requiring n-1 comparisons); should it be out of order, the computer triggers its "destroy universe" operation. Only in the surviving universes will there be observers to see that the randomisation worked first time and that the list is in sorted order.

Note, however, that even here there is no free lunch -- while this algorithm is O(n) in time, permuting the list requires that we consume O(n log n) bits of quantum randomness.

Some caution is needed over the choice of algorithms suitable for adaptation to such a quantum computer. For instance, the bozosort is very unlikely to succeed in one iteration and for many inputs (in which there is more than just one pair of elements out of order) it cannot succeed in one iteration. For those inputs, observers would be surprised by mysterious failures of the computer or improbable accidents preventing its operation because all universes in which it did operate are destroyed.

[edit] External links