Bogosort - Running Time and Termination

Running Time and Termination

This sorting algorithm is probabilistic in nature. If all elements to be sorted are distinct, the expected number of comparisons in the average case is asymptotically equivalent to, and the expected number of swaps in the average case equals . The expected number of swaps grows faster than the expected number of comparisons, because if the elements are not in order, this will usually be discovered after only a few comparisons no matter how many elements there are, but the work of shuffling the collection is proportional to its size. In the worst case, the number of comparisons and swaps are both unbounded, for the same reason that a tossed coin might turn up heads any number of times in a row.

The best case occurs if the list as given is already sorted; in this case the expected number of comparisons is, and no swaps at all are carried out.

For any collection of fixed size, the expected running time of the algorithm is finite for much 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 will almost surely eventually be chosen. However, if a pseudorandom number generator is used in place of a random source, it may never terminate, since these exhibit long-term cyclic behavior.

Read more about this topic:  Bogosort

Famous quotes containing the words running, time and/or termination:

    Swan/Mary Rutledge: Oh no, no. I’m not running away. I came here to get something, and I’m going to get it.
    Col. Cobb: Yes, but San Francisco is no place for a woman.
    Swan: Why not? I’m not afraid. I like the fog. I like this new world. I like the noise of something happening.... I’m tired of dreaming, Colonel Cobb. I’m staying. I’m staying and holding out my hands for gold—bright, yellow gold.
    Ben Hecht (1893–1964)

    The first time many women hold their tiny babies, they are apt to feel as clumsy and incompetent as any man. The difference is that our culture tells them they’re not supposed to feel that way. Our culture assumes that they will quickly learn how to be a mother, and that assumption rubs off on most women—so they learn.
    Pamela Patrick Novotny (20th century)

    We hoped for a happy termination of this terrible war long before this; but God knows best, and has ruled otherwise.
    Abraham Lincoln (1809–1865)