Comparison Sort - Performance Limits and Advantages of Different Sorting Techniques

Performance Limits and Advantages of Different Sorting Techniques

There are fundamental limits on the performance of comparison sorts. A comparison sort must have a lower bound of Ω(n log n) comparison operations. This is a consequence of the limited information available through comparisons alone — or, to put it differently, of the vague algebraic structure of totally ordered sets. In this sense, mergesort, heapsort, and introsort are asymptotically optimal in terms of the number of comparisons they must perform, although this metric neglects other operations. The three non-comparison sorts above achieve O(n) performance by using operations other than comparisons, allowing them to sidestep this lower bound (assuming elements are constant-sized).

Nevertheless, comparison sorts offer the notable advantage that control over the comparison function allows sorting of many different datatypes and fine control over how the list is sorted. For example, reversing the result of the comparison function allows the list to be sorted in reverse; and one can sort a list of tuples in lexicographic order by just creating a comparison function that compares each part in sequence:

function tupleCompare((lefta, leftb, leftc), (righta, rightb, rightc)) if lefta ≠ righta return compare(lefta, righta) else if leftb ≠ rightb return compare(leftb, rightb) else return compare(leftc, rightc)

Balanced ternary notation allows comparisons to be made in one step, whose result will be one of "less than", "greater than" or "equal to".

Comparison sorts generally adapt more easily to complex orders such as the order of floating-point numbers. Additionally, once a comparison function is written, any comparison sort can be used without modification; non-comparison sorts typically require specialized versions for each datatype.

This flexibility, together with the efficiency of the above comparison sorting algorithms on modern computers, has led to widespread preference for comparison sorts in most practical work.

Read more about this topic:  Comparison Sort

Famous quotes containing the words performance, limits, advantages and/or techniques:

    Still be kind,
    And eke out our performance with your mind.
    William Shakespeare (1564–1616)

    Europe has what we do not have yet, a sense of the mysterious and inexorable limits of life, a sense, in a word, of tragedy. And we have what they sorely need: a sense of life’s possibilities.
    James Baldwin (1924–1987)

    ... is it not clear that to give to such women as desire it and can devote themselves to literary and scientific pursuits all the advantages enjoyed by men of the same class will lessen essentially the number of thoughtless, idle, vain and frivolous women and thus secure the [sic] society the services of those who now hang as dead weight?
    Sarah M. Grimke (1792–1873)

    It is easy to lose confidence in our natural ability to raise children. The true techniques for raising children are simple: Be with them, play with them, talk to them. You are not squandering their time no matter what the latest child development books say about “purposeful play” and “cognitive learning skills.”
    Neil Kurshan (20th century)