it is not possible to randomly shuffle the input. If used without this shuffling, it could easily degenerate into quadratic behaviour. One weakness of insertion sort is that it may require a high number of swap operations and be costly if memory write is expensive. Library sort may improve that somewhat in the insertion step, as fewer elements need to move to make room, but is also adding an extra cost in the rebalancing step. In addition, locality of reference will be poor compared to mergesort as each insertion from a random data set may access memory that is no longer in cache, especially with large data sets. Implementation Algorithm Let us say we have an array of n elements. We choose the gap we intend to give. Then we would have a final array of size (1 + ε)n. The algorithm works in log n rounds. In each round we insert as many elements as there are in the final array already, before re-balancing the array. For finding the position of inserting, we apply Binary Search in the final array and then swap the following elements till we hit an empty space. Once the round is over, we re-balance the final array by inserting spaces between each element. Following are three important steps of the algorithm: Binary Search: Finding the position of insertion by applying binary search within the already inserted elements. This can be done by linearly moving towards left or right side of the array if you hit an empty space in the middle element. Insertion: Inserting the element in the position found and swapping the following elements by 1 position till an empty space is hit. This is done in logarithmic time, with high probability. Re-Balancing: Inserting spaces between each pair of elements in the array. The cost of rebalancing is linear in the number of elements already inserted. As these lengths increase with the powers of 2 for each round, the total cost of rebalancing is also linear. Pseudocode procedure rebalance(A, begin, end) is r ← end w ← end ÷ 2 while r ≥ begin do A[w+1] ← gap A[w] ← A[r] r ← r − 1 w ← w − 2 procedure sort(A) is n ← length(A) S ← new array of n gaps for i ← 1 to floor(log2(n) + 1) do for j ← 2^i to 2^(i + 1) do ins