Rotated Library Sort

This paper investigates how to improve the worst case runtime of Insertion Sort while keeping it in-place, incremental and adaptive. To sort an array of n elements with w bits for each element, classic Insertion Sort runs in O(n2) operations with wn bits space. Gapped Insertion Sort has a runtime of O(n lg n) with a high probability of only using (1 + e)wn bits space. This paper shows that Rotated Insertion Sort guarantees O(√n lg n) operations per insertion and has a worst case sorting time of O(n1.5 lg n) operations by using optimal O(w) auxiliary bits. By using extra Θ(√n lg n) bits and recursively applying the same structure l times, it can be done with O(2l n1+1/l) operations. Apart from the space usage and time guarantees, it also has the advantage of efficiently retrieving the i-th element in constant time. This paper presents Rotated Library Sort that combines the advantages of the above two improved approaches.