Adaptive Sort - Examples

Examples

A classic example of an adaptive sorting algorithm is Straight Insertion Sort. In this sorting algorithm, we scan the input from left to right, repeatedly finding the position of the current item, and insert it into an array of previously sorted items.

In pseudo-code form, the Straight Insertion Sort algorithm could look something like this:

procedure Straight Insertion Sort (X, n): X := − ∞; for j := 2 to n do begin i := j − 1; t := X; while t < X do begin X := X; i := i - 1 end; X := t; end;

The performance of this algorithm can be described in terms of the number of inversions in the input, and then T(n) will be roughly equal to I(A) + (n - 1), where I(A) is the number of Inversions. Using this measure of presortedness – being relative to the number of inversions – Straight Insertion Sort takes less time to sort the closer it is to being sorted.

Other examples of adaptive sorting algorithms are Adaptive Heap-Sort and Adaptive Merge-Sort. Dijkstra’s Smoothsort algorithm is a variation on heap-sort that is also considered an adaptive sorting algorithm.

Timsort, used as the generic sorting algorithm for several programming languages including Python, is adaptive.

Read more about this topic:  Adaptive Sort

Famous quotes containing the word examples:

    In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.
    Michel de Montaigne (1533–1592)

    No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.
    André Breton (1896–1966)

    It is hardly to be believed how spiritual reflections when mixed with a little physics can hold people’s attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.
    —G.C. (Georg Christoph)