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:

    It’s not like I was out there running and not knowing what’s going on in the country. I knew what was going on, but I felt this is not something that is going to bog me down and not let me participate. The only way I was going to make a difference for myself or any other black person is to say the hurdles were there and do what I had to do.
    Wyomia Tyus (b. 1945)

    How often should a woman be pregnant? Continually, or hardly ever? Or must there be a certain number of pregnancy anniversaries established by fashion? What do you, at the age of forty-three, have to say on the subject? Is it a fact that the laws of nature, or of the country, or of propriety, have ordained this time of life for sterility?
    Philip Dormer Stanhope, 4th Earl Chesterfield (1694–1773)

    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)