Contents    Page-10    Prev    Next    Page+10    Index   

Sorting

Sorting a set of items into order is a very common task in Computer Science.

There are a number of bad algorithms that sort in O(n2) time; we will not discuss those much. We have already seen algorithms that do sorting in O(n · log(n)) time, and in fact it can be proved that that is the best possible.

An internal sort is performed entirely in main memory. If the set of items is too large to fit in memory, an external sort using disk or other external storage can be done.

Sorting is based on comparison between items. In general, complex data can be compared and sorted in many ways. It is common to furnish a comparison function to the sorting program:


>(sort '(32 29 62 75 48 14 80 98 28 19) '<)

(14 19 28 29 32 48 62 75 80 98)


>(sort '(32 29 62 75 48 14 80 98 28 19) '>)

(98 80 75 62 48 32 29 28 19 14)

A good resource is www.sorting-algorithms.com