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:

    There are many examples of women that have excelled in learning, and even in war, but this is no reason we should bring ‘em all up to Latin and Greek or else military discipline, instead of needle-work and housewifry.
    Bernard Mandeville (1670–1733)

    Histories are more full of examples of the fidelity of dogs than of friends.
    Alexander Pope (1688–1744)

    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)