A sorting algorithm is called adaptive with respect
to some measure of presortedness if, for some given
input size, the running time of the algorithm is provably
better for inputs with low value of the measure. Perhaps
the most well-known measure is Inv, the number of
inversions (i.e. pairs of elements that are in the wrong
order) in the input. Other measures of presortedness
include Rem, the minimum number of elements that
must be removed for the remaining elements to be
sorted, and Runs, the number of consecutive ascending
runs. More examples of measures can be found in [5].
An example of an adaptive sorting algorithm is insertion
sort using level-linked B-trees with nger searches for
locating each new insertion point [13], which sorts in
O(n(1 + log(1 + Inv=n))) time. In the comparison
model, this is known to be optimal with respect to the
measure Inv [5].