Comb Sort

Comb sort is a relatively simplistic sorting algorithm originally designed by Włodzimierz Dobosiewicz in 1980. Later it was rediscovered and popularized by Stephen Lacey and Richard Box with a Byte Magazine article published in April 1991. Comb sort improves on bubble sort, and rivals algorithms like Quicksort (visual comparison). The basic idea is to eliminate turtles, or small values near the end of the list, since in a bubble sort these slow the sorting down tremendously. Rabbits, large values around the beginning of the list, do not pose a problem in bubble sort.

In bubble sort, when any two elements are compared, they always have a gap (distance from each other) of 1. The basic idea of comb sort is that the gap can be much more than 1 (Shell sort is also based on this idea, but it is a modification of insertion sort rather than bubble sort).

In other words, the inner loop of bubble sort, which does the actual swap, is modified such that gap between swapped elements goes down (for each iteration of outer loop) in steps of shrink factor. i.e. . Unlike in bubble sort, where the gap is constant i.e. 1.

The gap starts out as the length of the list being sorted divided by the shrink factor (generally 1.3; see below), and the list is sorted with that value (rounded down to an integer if needed) as the gap. Then the gap is divided by the shrink factor again, the list is sorted with this new gap, and the process repeats until the gap is 1. At this point, comb sort continues using a gap of 1 until the list is fully sorted. The final stage of the sort is thus equivalent to a bubble sort, but by this time most turtles have been dealt with, so a bubble sort will be efficient.

Read more about Comb Sort:  Shrink Factor

Famous quotes containing the words comb and/or sort:

    And still we wear our uniforms, follow
    The cracked cry of the bugles, comb and brush
    Our pride and prejudice, doctor the sallow
    Initial ardor, wish to keep it fresh.
    Still we applaud the President’s voice and face.
    Gwendolyn Brooks (b. 1917)

    Both the Moral Majority, who are recycling medieval language to explain AIDS, and those ultra-leftists who attribute AIDS to some sort of conspiracy, have a clearly political analysis of the epidemic. But even if one attributes its cause to a microorganism rather than the wrath of God, or the workings of the CIA, it is clear that the way in which AIDS has been perceived, conceptualized, imagined, researched and financed makes this the most political of diseases.
    Dennis Altman (b. 1943)