An Optimal Adaptive In-place Sorting Algorithm

We consider the problem of taking advantage of existing order within the input sequence when sorting. The measure of presortedness used is the number of inversions. We first introduce a simple algorithm, and using this as a building block an in-place sorting algorithm which optimally adapts to the number of inversions is obtained. Furthermore, it optimally adapts to another important measure of presortedness, namely Rem, the minimum number of elements that have to be removed from a sequence to leave a sorted sequence.