<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Fast-Insertion-Sort: a New Family of E cient Variants of the Insertion-Sort Algorithm y</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Simone Faro</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Francesco Pio Marino</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Stefano Sca ti</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Universita di Catania</institution>
          ,
          <addr-line>Viale A.Doria n.6, 95125 Catania</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <fpage>37</fpage>
      <lpage>48</lpage>
      <abstract>
        <p>In this paper we present Fast-Insertion-Sort, a sequence of efcient external variants of the well known Insertion-Sort algorithm which achieve by nesting an O(n1+") worst-case time complexity, where " = h1 , for h 2 N. Our new solutions can be seen as the generalization of Insertion-Sort to multiple elements block insertion and, likewise the original algorithm, they are stable, adaptive and very simple to translate into programming code. Moreover they can be easily modi ed to obtain in-place variations at the cost of a constant factor. Moreover, by further generalizing our approach we obtain a representative recursive algorithm achieving O(n log n) worst case time complexity. From our experimental results it turns out that our new variants of the Insertion-Sort algorithm are very competitive with the most e ective sorting algorithms known in literature, outperforming fast implementations of the Hoare's Quick-Sort algorithm in many practical cases, and showing an O(n log n) behaviour in practice.</p>
      </abstract>
      <kwd-group>
        <kwd>Sorting Insertion-Sort Design of Algorithms</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>Sorting is one of the most fundamental and extensively studied problems in
computer science, mainly due to its direct applications in almost all areas of
computing and probably it still remains one of the most frequent tasks needed
in almost all computer programs.</p>
      <p>Formally sorting consists in nding a permutation of the elements of an input
array such that they are organized in an ascending (or descending) order. In the
comparison based model, it is well-known that the lower bound for sorting n
distinct elements is (n log n), both in the worst case and in the average case.1</p>
      <p>A huge number of e cient sorting algorithms have been proposed over the
years with di erent features.2 There are several factors indeed a ecting the
selec</p>
      <p>Insert(A; i)
1. j i 1
2. v A[i]
3. while (j 0 and A[j] &gt; v) do
4. A[j + 1] A[j]
5. j j 1
6. A[j + 1] v</p>
      <p>
        InsertionSort
1. for i 1 to n 1 do
2. Insert(A; i)
tion of suitable sorting algorithm for an application [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ]. Among them the time
and space complexity of an algorithm, its stability, its adaptability, its
capability to work online, the number of elements to be sorted, their distribution and
the percentage of already sorted elements, are considered as direct factors [
        <xref ref-type="bibr" rid="ref21">21</xref>
        ]
whereas programming complexity and data type of elements are included among
the indirect factors [
        <xref ref-type="bibr" rid="ref20">20</xref>
        ]. In our discussion we will refer to the time complexity
of a sorting algorithm as the overall number of any operation performed during
its execution.
      </p>
      <p>
        The space complexity of an algorithm concerns the total amount of working
space (in addition to the array to be sorted) required in the worst case. An
inplace algorithm requires only constant additional space, otherwise it is said to
be an external algorithm. However, in literature, many recursive algorithms are
said to work in-place (using ambiguous terminology) even if they do not, since
they require a stack of logarithmic height. In this case we say that the algorithm
is internal [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. For instance Quick-Sort [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] is an internal algorithm, Merge-Sort
adopts external sorting since it uses a linear amount of working space for merges,
while Insertion-Sort is a real in-place algorithm.
      </p>
      <p>The focus of many sorting algorithms lies instead on practical methods whose
running time outperforms standard techniques even when comparisons are cheap.
In this case expected (rather than worst case) performances is the main concern.
Among this class of algorithms, despite its higher number of comparisons than
for other methods, Quick-Sort and most of its variants are generally considered
the fastest general purpose sorting methods.</p>
      <p>
        The Insertion-Sort algorithm, particularly relevant for this paper, is also
considered one of the best and most exible sorting methods despite its quadratic
worst case time complexity, mostly due to its stability, good performances,
simplicity, in-place and online nature. It is a simple iterative sorting procedure that
incrementally builds the nal sorted array. Its pseudocode is depicted in Fig. 1.
The i-th iteration of the algorithm takes at most O(i) time, for a total O(n2)
time complexity in both worst and average case.
Algorithm twc
Insertion-Sort O(n2)
Rotated-IS [
        <xref ref-type="bibr" rid="ref22">22</xref>
        ] O(n1:5 log n)
Controlled-Density-IS [
        <xref ref-type="bibr" rid="ref18">18</xref>
        ] O(n1:5)
Library-Sort [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] O(n2)
Binary-IS [
        <xref ref-type="bibr" rid="ref27">27</xref>
        ] O(n2)
2-Element-IS [
        <xref ref-type="bibr" rid="ref19">19</xref>
        ] O(n2)
Enhanced-IS [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ] O(n2)
Adaptive-IS [
        <xref ref-type="bibr" rid="ref23">23</xref>
        ] O(n2)
Doubly-IS [
        <xref ref-type="bibr" rid="ref24">24</xref>
        ] O(n2)
Bidirectional-IS [
        <xref ref-type="bibr" rid="ref21">21</xref>
        ] O(n2)
Brownian-Motus-IS [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] O(n2)
Clustered-Binary-IS [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] O(n2)
Block-Insertion-Sort O(n1:5)
Fast-Insertion-Sort(h) O(n1+ h1 )
Fast-Insertion-Sort O(n1+")
cwc space tac tbc year
O(n2) O(1) O(n2) O(n) {
      </p>
      <p>O(w)? O(n2) 1979</p>
      <p>O(n) O(n log n) 1980
O(n log n) O(n) O(n log n) O(n) 2006
O(n log n) O(1) O(n2) O(n log n) 2008
O(n2) O(1) O(n2) O(n) 2010
O(n2) O(n) O(n2) O(n) 2013
O(n log n) O(1) O(n2) O(n) 2014
O(n2) O(1) O(n2) O(n) 2015
O(n2) O(1) O(n1:5) O(n2) 2017
O(n2) O(1) O(n2) O(n) 2018
O(n log n) O(1) O(n2) O(n) 2018
O(n log n) O(1)[ O(n log n)x O(n) 2019
O(n log n) O(1)[ O(n log n)x O(n) 2019</p>
      <p>O(n log n) O(1)[ O(n log n)x O(n) 2019</p>
      <p>
        The Insertion-Sort algorithm is also adaptive, achieving O( n) worst case time
complexity when each element in the input array is no more than places away
from its sorted position. Moreover it has an enviable linear best case time (which
occurs when the input array is already sorted) and can be immediately translated
into programming code (see Bentley [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] for a simple 3-lines implementation of
Insertion-Sort in the C programming language).
      </p>
      <p>
        Much more interesting, Insertion-Sort is one of the fastest algorithms for
sorting very small arrays, even faster than Quicksort [
        <xref ref-type="bibr" rid="ref33">33</xref>
        ]. Indeed, e cient Quick
Sort implementations use Insertion-Sort as a subroutine for arrays smaller than a
given threshold [
        <xref ref-type="bibr" rid="ref28 ref29 ref35">28, 29, 35</xref>
        ]. Such threshold should be experimentally determined
and depends on the machine. However it is commonly around 10 elements.
      </p>
      <p>Due to such many advantages the Insertion-Sort algorithm has inspired much
work and is the progenitor of several algorithmic variants which aim at reducing
comparisons and element moves very e ciently. Table 1 presents a list of most
of e ective variants of Insertion-Sort portrayed in terms of several features.</p>
      <p>
        For the sake of completeness we also report the some related algorithms
obtained as the combination of Merge-Sort and Insertion-Sort [
        <xref ref-type="bibr" rid="ref17 ref34 ref5 ref6">6, 5, 34, 17</xref>
        ] which,
although not of practical signi cance, remain of theoretical interest.
      </p>
      <p>In this paper we present a new family of e cient external algorithms inspired
by Insertion-Sort, where each element of the family, named Fast-Insertion-Sort(h)
for h 2 N, achieves an O(n1+ h1 ) worst-case time complexity by nesting previous
algorithms of the same family. Although Fast-Insertion-Sort(h) requires O(n1 h1 )
additional space we show how to translate it into an in-place solution at the
cost of a constant factor. In addition we also devise a purely recursive
generalized version of our Fast-Insertion-Sort(h) algorithms, which achieves an O(n log n)
worst case time complexity. Like Insertion-Sort our solutions are stable, adaptive
and very simple to translate into programming code.</p>
      <p>Surprisingly, it turns out from our experimental results that our variants
of the Insertion-Sort algorithm are very e ective in practical cases showing an
O(n log n) behaviour in practice. Their performances are comparable to that
of the most e ective sorting algorithms known in literature, overcoming fast
implementations of the Hoare's Quick-Sort algorithm in many practical cases.</p>
      <p>Throughout the paper we will use the following terminology. Given an array
A[0::n 1], of size n, we denote by A[i] the (i + 1)-st element of A, for 0 i &lt; n,
and with A[i::j] the portion of the array contained between the (i + 1)-st and
the (j + 1)-st characters of A, for 0 i j &lt; m. We indicate by (A + i) the
array beginning at (i + 1)-st position of A, so that (A + i)[0::j] = A[i::j].
2</p>
      <p>The Fast-Insertion-Sort Algorithms
In this section we present Fast-Insertion-Sort, a new family of e cient sorting
algorithms obtained as natural generalizations to multiple elements insertion of
the standard Insertion-Sort algorithm. The underlying idea is to extend, at each
iteration, the left portion of the array by means of the insertion of a sorted block
of k elements, with k 2. Despite its simplicity, this approach surprisingly leads,
under suitable conditions, to a family of very e cient algorithms, both in theory
and in practice, whose behaviour moves close to a linear trend for increasing
values of the input size.</p>
      <p>The new family is a sequence of nested algorithms, Fast-Insertion-Sort(h), for
h 2 N, where the h-th algorithm can be applied when n &gt; 2h. The pseudocode of
the Fast-Insertion-Sort(h) algorithm and its auxiliary procedure Insert-Block
are depicted in Fig. 2.</p>
      <p>Each algorithm in the sequence solves the problem by nesting function calls
to previous algorithms in the same sequence and is associated with an integer
parameter h &gt; 0 which substantially represents the depth of such a nesting. For
this reason in the execution of the Fast-Insertion-Sort(h) algorithm it is assumed
that the size of the input array is at least 2h.</p>
      <p>The following de nition of input size degree is particularly useful for the
characterization of our algorithm.</p>
      <p>De nition 1 (Input size degree). Given an input array of size n and a
constant parameter c 2, we say that its input size degree (or simply its degree)
is h, with reference to c, if ch 1 &lt; n ch. We refer to the constant value c
as the partitioning factor. When c is clear from the context we simply say that
the input size degree is h. We can easily compute the degree of the input n by
h = dlogc(n)e.
Insert-Block(A; i; k; T ) Fast-Insertion-Sort(h)(A; n)
1. for j 0 to k 1 do 1. if n 2h 1 then h dlog2(n)e
2. Swap(T [j]; A[i + j]) 2. k n(h 1)=h
3. ` k 1 3. T
4. j i 1 4. for i
5. while ` 0 do 5.
6. while j 0 and A[j] &gt; T [`] 6.
7. Swap(A[j + ` + 1]; A[j]) 7.
8. j j 1
9. Swap(A[j + ` + 1]; T [h])
10. ` ` 1
array[k]</p>
      <p>0 to n (step k) do
b min(k; n i)
Fast-Insertion-Sort(h 1)(A + i; b)
Insert-Block(A; i; b; T )</p>
      <p>Note 1 (Block partitioning). If the the input array has degree h then the
algorithm performs a partitioning of the array in at most c blocks of size k = n1 h1 .
In the worst case, indeed, n = ch and the number of blocks is given by
n
k
=</p>
      <p>n
n1 h1</p>
      <p>l 1 m
= n h
= l ch h1 m = c
In addition observe that each block of size k represents an array of degree h
Indeed, if ch 1 &lt; n ch then k = n1 h1 is bounded by
1.
ch 2 &lt; ch 2+ h1 &lt; ch 1 1 h1 &lt; k
ch 1 h1 = ch 1
Observe that if n &lt; ch then the last block has size greater than 0 and less than
k, thus we have no guarantees that such size has degree equal to h 1.</p>
      <p>The algorithm is based on an iterative cycle on the variable i. At the
beginning of each iteration, the left portion of the array, A[0::i 1], is assumed to be
already sorted. Then the algorithm sorts the elements in the block A[i::i + k 1],
of size k, by a nested call to Fast-Insertion-Sort(h 1), and tidily insert all the
elements of the block in the sorted portion of the array by means of
procedure Insert-Block. The overall number of iterations is then equal to dn=ke,
where the size of the last block my be less than k and speci cally it has size
n k(dn=ke 1).</p>
      <p>A call to procedure Insert-Block(A; i; k; T ) has the e ect to insert the
block A[i::i + k 1], of size k, into the left side of the array A[0::i 1], using the
array T as a working area. It is assumed that both A[0::i 1] and A[i::i + k 1]
have both been sorted. During the insertion process elements of the left portion
will be moved over the elements of the right block in order to make room for
the insertions. The additional array T , of size k, is used to temporarily store the
elements of the right block so that they are not overwritten.</p>
      <p>Note 2. Since procedure Insert-Block uses external memory for temporarily
storing the elements of the block A[i::i + k 1], all swap operations (Swap(a; b))
inside the procedure (lines 2, 7 and 9), may be replaced by element moves (a
b), cutting down the number of assignements of a factor up to 3.</p>
      <p>The insertion process iterates over the elements of the right block (now
temporarily moved on T ) proceeding from right to left (while cycle of line 5). For
each element T [`], with 0 ` &lt; k, the algorithm iterates over the elements
A[j] of the left block, proceeding from right to left, in order to nd the correct
position where T [`] must be placed (while cycle of line 6). If the element A[j] is
greater than T [`] then it is moved of ` position to the right (line 7). Once the
rst element A[j], such that A[j] T [`], is found (or j &lt; 0), T [`] is moved at
position A[j + ` + 1] and ` is decreased (lines 9-10).</p>
      <p>
        Note 3. For simplicity procedure Insert-Block shown in Fig. 2 uses a linear
search for locating the correct position where an element must be placed. It
takes at most O(i) comparisons, if i is the size of the sorted portion of the array.
However it is more favourable to use a binary search [
        <xref ref-type="bibr" rid="ref27">27</xref>
        ] which would allow to
reduce the number of comparisons to O(log i).
      </p>
      <p>It is easy to prove that all Fast-Insertion-Sort(h) algorithms maintain all the
features of the standard Insertion-Sort algorithm and speci cally they guarantee
a stable sorting and are very simple to implement. However a drawback of this
family of algorithms is that they use additional external memory of size O(k).
In the Section 2.1 we show how to obtain in-place variants of such algorithms.</p>
      <p>Observe that Fast-Insertion-Sort(1) corresponds to the standard Insertion-Sort
algorithm where k = n0 = 1 and each block consists in a single element.</p>
      <p>
        The algorithm Fast-Insertion-Sort(2) devises a special mention since it can be
easily translated into a purely iterative in-place online adaptive sorting
algorithm. Due to its distinctiveness we give it a special name: Block-Insertion-Sort.
It can be proved that if we set k = pn then the worst-case time complexity of
Block-Insertion-Sort is O(n1:5). Although there are few variants [
        <xref ref-type="bibr" rid="ref18 ref22">22, 18</xref>
        ] achieving
o(n2) worst case time complexity using additional space, to the best of our
knowledge this is the rst time an iterative in-place online variant of the Insertion-Sort
algorithm achieves a o(n2) complexity in the worst case.
      </p>
      <p>The sequence of algorithms Fast-Insertion-Sort(h), for h 2 N, converge to a
purely recursive algorithm which could be seen as the representative of the family
and which, for this reason, we name simply Fast-Insertion-Sort. The pseudocode
of the Fast-Insertion-Sort algorithm is depicted in Fig. 4. It maintains the main
structure of the Fast-Insertion-Sort(h) algorithms but dynamically computes the
value of the input size degree h. Speci cally, given a partitioning parameter c 2,
the algorithm computes the input size degree as h = dlogc(n)e. The choice of
the partitioning parameter c could be critical for the practical performances of
the algorithm3. Note that, for c = 2, Fast-Insertion-Sort exactly behaves like
3 As discussed in Section 3 the best choice for the partitioning parameter, leading to
the best performances in practical cases, is to set c = 5.</p>
      <p>Fig. 3. Three schemas for the insertion of
(A) a sorted block of size k into A[0::i 1].</p>
      <p>Two blocks are involved: the working area
w which represents the block to be
inserted, and a storage area s, which is used
(B) to temporarily store elements of the
working area. In schema (A) an external storage
area T is used. In schema (B) the
contiguous block A[i + k::i + 2k 1] is used as
(C) storage area. In schema (C) we insert the
block A[i + k::i + 2k 1] and use the block
A[i::i + k 1] as storage area.</p>
      <p>Merge-Sort, since the process of inserting a sorting block into another one can
be viewed as a merging procedure. It can be proved that the Fast-Insertion-Sort
algorithm has a O(n log n) worst case time complexity. Moreover such algorithm
shows also very good performances in practical cases, as discussed in Section 3.
2.1</p>
      <p>In-Place Sorting
In this section we brie y describe how to allow Fast-Insertion-Sort algorithms
to use an internal storage area to temporarily save the elements of the working
area representing the block which should be inserted during the current iteration,
making it an in-place sorting algorithm4.</p>
      <p>In order to make sure that the contents of the storage area is not lost, it
is su cient to guarantee that whenever an element should be moved from the
working area, it is swapped with the element occupying that respective
position in the storage area. Procedure Insert-Block, shown in Fig. 2, makes this
guarantees.</p>
      <p>In this context it should be possible to use the contiguous block A[i + k::i +
2k 1], of size k, as storage area, as depicted in Schema B of Fig. 3. This could be
obtained by replacing the procedure call Insert-Block(A; i; k; T ) (line 6) with
Insert-Block(A; i; k; A + k). The main advantage of this approach is that the
part of the array that is not currently being sorted can be used as temporary
storage area. This yields a fast variant for the Fast-Insertion-Sort(h) algorithm
which works in-place requiring only constant extra space.</p>
      <p>
        However, since the insertion of a block of size k requires a contiguous block
of k elements, at the last iteration, when i &gt; n 2k, there is not enough space to
allow the algorithm to work in-place. Although many solutions may be adopted
to address such case, we will prove it is enough to insert the elements of the last
4 This idea is not original since it has been successfully used in literature. The rst
sorting algorithm which introduced such a technique was the Quick-Heap-Sort
algorithm by Cantone and Cincotti [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. Recently it has been also adopted to obtain fast
internal variants of many recursive external sorting algorithms [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]
      </p>
      <p>Fast-Insertion-Sort(A; n)
1. if n 2 then
2. return Insertion-Sort(A; n)
3. h dlogc(n)e
4. k n(h 1)=h
5. T
6. for i
7.
8.
9.</p>
      <p>array[k]</p>
      <p>0 to n (step k) do
b min(k; n i)
Fast-Insertion-Sort(A + i; b)</p>
      <p>Insert-Block(A; i; b; T )
block, whose size is at most 2k 1, by individual insertions, as done by standard
Insertion-Sort.</p>
      <p>Thus at the beginning of each iteration the two blocks A[i::i + k 1] and
A[i + k::i + 2k 1] will be swapped. Subsequently, as in the previous case, the
algorithm sorts the block A[i::i + k 1], of size k, and insert it in the sorted
portion of the array, using the block A[i + k::i + 2k 1], as storage area.</p>
      <p>However, since all elements of the array must be inserted, sooner or later, it
is possible to avoid the k swap operation necessary to move the elements in the
storage area (lines 1-2 of procedure Insert-Block) by interchanging the two
blocks involved in the insertion process. Speci cally we can directly insert the
block A[i + k::i + 2k 1] using the block placed in the middle, i.e. A[i::i + k 1],
as storage area, as depicted in Schema C of Fig. 3.</p>
      <p>It is easy to prove that the resulting in-place variants of the
Fast-InsertionSort(h) algorithms maintain most of the features listed above: they work online
and are very simple to implement. Unfortunately, due to the swap operations
performed on the storage area, they don't guarantee a stable sorting and their
performance are a bit worse than the corresponding external variants.
3</p>
    </sec>
    <sec id="sec-2">
      <title>Experimental Evaluation</title>
      <p>
        In this section we present and comment the experimental results relative to a
comparison of our newly presented algorithms against some of the most e
ective sorting algorithms known in literature. Speci cally we tested the following
algorithms:
{ Merge-Sort (MS), the external algorithm with a (n log n) time and O(n)
space complexity. Here we implemented a version using only an array of size
dn=2e as storage space.
{ Heap-Sort (HS), an internal algorithm with a (n log n) time complexity.
{ Quick-Sort (QS), an internal algorithm with a O(n2) time complexity and
O(n log n) expected time. Here we implemented the standard Hoare's
algorithm with a random selection of the pivot element.
{ Quick-Sort (QS ), an optimized version of the Hoare's algorithm [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] which
uses Insertion-Sort for input size less or equal to 10.
{ Block-Insertion-Sort (BI), the in-place variant of algorithm described in
Section 2.
{ Fast-Insertion-Sort(h) (FIS(h)), the external variants of the nested algorithms
described in Section 2, for 2 h 10.
{ Fast-Insertion-Sort (FIS), the external variant of the recursive algorithm
described in Section 2, for 2 c 10.
{ Quick-Sort? (QS?), an optimized version of the Hoare's algorithm which uses
Block-Insertion-Sort for input sizes less or equal to 512.
      </p>
      <p>All algorithms have been implemented in the C++ programming language
and have been compiled with the GNU C++ Compiler 8.3.0, using the
optimization options -O2 -fno-guess-branch-probability. The codes of tested
algorithms are available at https://github.com/ostafen/Fast-Insertion-Sort.
All tests have been performed on a PC with a 3.40 GHz Intel Quad Core
i54670 processor, with 6144 KB cache memory, and running Linux Ubuntu 19.04.
Running times have been measured with a hardware cycle counter, available on
modern CPUs. We tested our algorithms on input arrays with a size n = 2i,
with 2 i 20. For each value of n we reported the mean over the running
times of 1000 runs.</p>
      <p>For each input size n, tests have been performed on arrays of integers and
speci cally on random arrays, partially ordered arrays, and reverse order
arrays. Random input sequences have been generated with a uniform distribution
in the interval [0 : : : 231], using the C++ random number generator. Partially
ordered arrays have been obtained by sorting random generated arrays and
subsequently executing a number of swaps equal to 1=4 of the input size. Fig. 5
summarizes the overall behaviour of the algorithms for the discussed
generation strategies. It turns out that the newly presented algorithms show in all
cases a O(n log n) behaviour in practice, outperforming Merge-Sort and
HeapSort (which are asymptotically optimal algorithms). Our new solutions are also
very competitive against the Quick-Sort algorithm, even for large sizes of the
input arrays. It is worth to notice that Fast-Insertion-Sort(h) algorithms show the
lowest running times for 2 h 4, while Fast-Insertion-Sort achieves the best
performance for c = 5. For small input size arrays, Block-Insertion-Sort obtains
good results, and this is why QS? turns out to be the Quick-Sort-based
algorithm with the best performances, outperforming the Quick-Sort implementation
which uses Insertion-Sort as a subroutine. The recursive algorithm
Fast-InsertionSort turns out to be faster than standard Quick-Sort in almost all cases, and
the gap turns out to be more sensible for very small and for very large input
arrays. In addition, while reverse order arrays represents the Quick-Sort worst
case scenario, algortithms in the Fast-Insertion-Sort family mantain their optimal
execution time once again, con rming to be among the most fast and exible
general purpose sorting alghoritms.</p>
      <p>Random Arrays</p>
      <p>microseconds
nanoseconds
milliseconds
32 64
centiseconds</p>
      <p>1024
deciseconds
10
16
128
256
512
2048
4096
8192
MS
QS
QS
QS?</p>
      <p>BI
FIS(h)
FIS
MS
QS
QS
QS?
eBI
FIS(h)
FIS
16384
32768
65536
131072
262144
524288</p>
      <p>1000000</p>
      <p>Partially Sorted Arrays
nanoseconds
microseconds
milliseconds
10
16
32 64
centiseconds
128
256
512
2048
4096</p>
      <p>8192
1024
deciseconds
0.4
0.2
0.6
0.4
0.2
0.4
0.2
0.6
0.4
0.2
16384
32768
65536
131072
262144
524288
1000000</p>
    </sec>
    <sec id="sec-3">
      <title>Conclusions</title>
      <p>In this paper we presented a new family of e cient, exible, stable, simple
sorting algorithms, named Fast-Insertion-Sort. The algorithms of such a new family
generalize the Insertion-Sort algorithm to multiple elements block insertion and
achieve an O(n1+") worst-case time complexity, where " = h1 , for h 2 N.
Moreover we generalized the basic idea obtaining a recursive algorithm achieving
O(n log n) worst case time complexity. We also discussed how to obtain in-place
variations of such algorithms by maintaining their main features. From our
experimental results it turns out that our solutions are very competitive with the
most e ective sorting algorithms, outperforming fast implementations of the
Hoare's Quick-Sort algorithm in many practical cases.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>M.</given-names>
            <surname>Bender</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Farach-Colton</surname>
          </string-name>
          , and
          <string-name>
            <surname>Mosteiro</surname>
          </string-name>
          , M.
          <source>Theory Comput Syst</source>
          ,
          <volume>39</volume>
          :
          <fpage>391</fpage>
          (
          <year>2006</year>
          ). https://doi.org/10.1007/s00224-005-1237-z
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>J.</given-names>
            <surname>Bentley</surname>
          </string-name>
          , Programming Pearls, ACM Press/Addison-Wesley, pp.
          <volume>116</volume>
          ,
          <issue>121</issue>
          (
          <year>2000</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>D.</given-names>
            <surname>Cantone</surname>
          </string-name>
          and
          <string-name>
            <surname>G. Cincotti,</surname>
          </string-name>
          <article-title>QuickHeapsort: an e cient mix of classical sorting algorithms</article-title>
          .
          <source>Theoretical Computer Science</source>
          ,
          <volume>285</volume>
          (
          <issue>1</issue>
          ) pp.
          <fpage>25</fpage>
          -
          <lpage>42</lpage>
          (
          <year>2002</year>
          ) DOI:
          <fpage>10</fpage>
          .1016/S0304-
          <volume>3975</volume>
          (
          <issue>01</issue>
          )
          <fpage>00288</fpage>
          -
          <lpage>2</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>P. S.</given-names>
            <surname>Dutta</surname>
          </string-name>
          ,
          <article-title>An approach to improve the performance of insertion sort algorithm</article-title>
          ,
          <source>International Journal of Computer Science and Engineering Technology</source>
          ,
          <volume>4</volume>
          ,
          <fpage>503</fpage>
          -
          <lpage>505</lpage>
          (
          <year>2013</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>S.</given-names>
            <surname>Edelkamp</surname>
          </string-name>
          , A. WeiB, S. Wild,
          <string-name>
            <surname>QuickXsort - A Fast Sorting</surname>
          </string-name>
          <article-title>Scheme in Theory and Practice</article-title>
          . CoRR abs/
          <year>1811</year>
          .01259 (
          <year>2018</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>L.R.</given-names>
            <surname>Ford</surname>
          </string-name>
          and
          <string-name>
            <given-names>S.M.</given-names>
            <surname>Jr. Johnson</surname>
          </string-name>
          , A tournament problem,
          <source>American Mathematical Monthly</source>
          ,
          <volume>66</volume>
          :
          <fpage>387</fpage>
          -
          <lpage>389</lpage>
          (
          <year>1959</year>
          ), doi:10.2307/2308750
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>R. M.</given-names>
            <surname>Frank</surname>
          </string-name>
          and
          <string-name>
            <given-names>R. B.</given-names>
            <surname>Lazarus</surname>
          </string-name>
          .
          <article-title>A High-Speed Sorting Procedure</article-title>
          .
          <source>Communications of the ACM</source>
          .
          <volume>3</volume>
          (
          <issue>1</issue>
          ):
          <fpage>20</fpage>
          -
          <lpage>22</lpage>
          (
          <year>1960</year>
          ) doi:10.1145/366947.366957.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8. V.
          <article-title>Ge ert</article-title>
          , J. Katajainen,
          <string-name>
            <given-names>T.</given-names>
            <surname>Pasanen</surname>
          </string-name>
          .
          <article-title>Asymptotically e cient in-place merging</article-title>
          .
          <source>Theoretical Computer Science</source>
          .
          <volume>237</volume>
          :
          <fpage>159</fpage>
          -
          <lpage>181</lpage>
          (
          <year>2000</year>
          ). doi:
          <volume>10</volume>
          .1016/S0304-
          <volume>3975</volume>
          (
          <issue>98</issue>
          )
          <fpage>00162</fpage>
          -
          <lpage>5</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <given-names>S.</given-names>
            <surname>Goel</surname>
          </string-name>
          and
          <string-name>
            <given-names>R.</given-names>
            <surname>Kumar</surname>
          </string-name>
          .
          <article-title>Brownian Motus and Clustered Binary Insertion Sort methods: An e cient progress over traditional methods</article-title>
          .
          <source>Future Generation Computer Systems</source>
          , vol.
          <volume>86</volume>
          , pp.
          <fpage>266</fpage>
          -
          <lpage>280</lpage>
          (
          <year>2018</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <given-names>T. N.</given-names>
            <surname>Hibbard</surname>
          </string-name>
          ,
          <article-title>An Empirical Study of Minimal Storage Sorting</article-title>
          .
          <source>Communications of the ACM</source>
          .
          <volume>6</volume>
          (
          <issue>5</issue>
          ):
          <fpage>206</fpage>
          -
          <lpage>213</lpage>
          (
          <year>1963</year>
          ) doi:10.1145/366552.366557.
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <given-names>C. A. R.</given-names>
            <surname>Hoare</surname>
          </string-name>
          . Algorithm 65:
          <string-name>
            <surname>Find</surname>
          </string-name>
          .
          <source>Commun. ACM</source>
          ,
          <volume>4</volume>
          (
          <issue>7</issue>
          ):
          <fpage>321</fpage>
          -
          <lpage>322</lpage>
          ,
          <year>July 1961</year>
          . URL: http://doi.acm.
          <source>org/10</source>
          .1145/366622.366647, doi:10.1145/366622.366647.
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          12.
          <string-name>
            <given-names>B.</given-names>
            <surname>Huang</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.A.</given-names>
            <surname>Langston</surname>
          </string-name>
          , Practical In-Place Merging.
          <source>Communications of the ACM</source>
          .
          <volume>31</volume>
          (
          <issue>3</issue>
          ):
          <fpage>348</fpage>
          -
          <lpage>352</lpage>
          (
          <year>1988</year>
          ). doi:
          <volume>10</volume>
          .1145/42392.42403.
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          13.
          <string-name>
            <surname>M. Khairullah</surname>
          </string-name>
          ,
          <article-title>Enhancing worst sorting algorithms</article-title>
          ,
          <source>International Journal of Advanced Science and Technology</source>
          ,
          <volume>56</volume>
          ,
          <fpage>13</fpage>
          -
          <lpage>26</lpage>
          (
          <year>2013</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          14.
          <string-name>
            <given-names>F.</given-names>
            <surname>Lam</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R. K.</given-names>
            <surname>Wong</surname>
          </string-name>
          ,
          <article-title>Rotated library sort</article-title>
          ,
          <source>Proceedings of the 19th Computing: The Australasian Theory Symposium</source>
          , Volume
          <volume>141</volume>
          , Australian Computer Society, Inc., pp.
          <fpage>21</fpage>
          -
          <lpage>26</lpage>
          ,
          <year>2013</year>
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          15.
          <string-name>
            <surname>J. Katajainen</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          <string-name>
            <surname>Pasanen</surname>
            and
            <given-names>J.</given-names>
          </string-name>
          <string-name>
            <surname>Teuhola</surname>
          </string-name>
          ,
          <article-title>Practical in-place mergesort</article-title>
          .
          <source>Nordic J. Computing</source>
          .
          <volume>3</volume>
          (
          <issue>1</issue>
          ):
          <fpage>27</fpage>
          -
          <lpage>40</lpage>
          (
          <year>1996</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          16.
          <string-name>
            <given-names>P.</given-names>
            <surname>Kim</surname>
          </string-name>
          and
          <string-name>
            <given-names>A.</given-names>
            <surname>Kutzner</surname>
          </string-name>
          .
          <article-title>Stable Minimum Storage Merging by Symmetric Comparisons</article-title>
          .
          <source>European Symp. Algorithms. Lecture Notes in Computer Science 3221</source>
          . pp.
          <fpage>714</fpage>
          -
          <lpage>723</lpage>
          (
          <year>2004</year>
          ).
          <source>doi:10.1007/978-3-540-30140-0 63. ISBN 978-3-540-23025-0</source>
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          17.
          <string-name>
            <given-names>A.</given-names>
            <surname>Kutzner</surname>
          </string-name>
          , P. Kim,
          <source>Ratio Based Stable In-Place Merging. Lecture Notes in Computer Science</source>
          ,
          <volume>4978</volume>
          . Springer Berlin Heidelberg. pp.
          <fpage>246</fpage>
          -
          <lpage>257</lpage>
          (
          <year>2008</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          18.
          <string-name>
            <given-names>R.</given-names>
            <surname>Melville</surname>
          </string-name>
          and
          <string-name>
            <given-names>D.</given-names>
            <surname>Gries</surname>
          </string-name>
          .
          <article-title>Controlled density sorting</article-title>
          .
          <source>In Information Processing Letters</source>
          ,
          <volume>10</volume>
          :
          <fpage>4</fpage>
          ,
          <fpage>pages169</fpage>
          -
          <lpage>172</lpage>
          ,
          <year>1980</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          19. W. Min,
          <article-title>Analysis on 2-element insertion sort algorithm</article-title>
          .
          <source>Proceedings of International Conference on Computer Design and Applications (ICCDA)</source>
          , Vol.
          <volume>1</volume>
          , IEEE, pp.
          <fpage>143</fpage>
          -
          <lpage>146</lpage>
          (
          <year>2010</year>
          ). doi:
          <volume>10</volume>
          .1109/ICCDA.
          <year>2010</year>
          .
          <volume>5541165</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          20.
          <string-name>
            <surname>A. D. Mishra</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          <string-name>
            <surname>Garg</surname>
          </string-name>
          , Selection of best sorting algorithm,
          <source>International Journal of Intelligent Information Processing, 435</source>
          <volume>2</volume>
          (
          <issue>2</issue>
          ) (
          <year>2008</year>
          )
          <fpage>363</fpage>
          -
          <lpage>368</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          21.
          <string-name>
            <given-names>A. S.</given-names>
            <surname>Mohammed</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S. E.</given-names>
            <surname>Amrahov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F. V.</given-names>
            <surname>Celebi</surname>
          </string-name>
          ,
          <article-title>Bidirectional conditional insertion sort algorithm; An e cient progress on the classical insertion sort</article-title>
          ,
          <source>Future Generation Computer Systems</source>
          ,
          <volume>71</volume>
          , pp.
          <fpage>102</fpage>
          -
          <lpage>112</lpage>
          (
          <year>2017</year>
          ). doi:
          <volume>10</volume>
          .1016/j.future.
          <year>2017</year>
          .
          <volume>01</volume>
          .034.
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          22.
          <string-name>
            <given-names>J. I.</given-names>
            <surname>Munro</surname>
          </string-name>
          and
          <string-name>
            <given-names>H.</given-names>
            <surname>Suwanda</surname>
          </string-name>
          ,
          <article-title>Implicit data structures</article-title>
          ,
          <source>in STOC 79, Proceedings of the eleventh annual ACM symposium on Theory of computing</source>
          , ACM Press, pp.
          <fpage>108</fpage>
          -
          <lpage>117</lpage>
          (
          <year>1979</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref23">
        <mixed-citation>
          23.
          <string-name>
            <given-names>K.</given-names>
            <surname>Nenwani</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Mane</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Bharne</surname>
          </string-name>
          ,
          <article-title>Enhancing adaptability of insertion sort through 2-way expansion</article-title>
          ,
          <source>Proceedings of 5th International Conference on Con uence The Next Generation Information Technology Summit (Con uence)</source>
          , IEEE, pp.
          <fpage>843</fpage>
          -
          <lpage>847</lpage>
          (
          <year>2014</year>
          ). doi:
          <volume>10</volume>
          .1109/CONFLUENCE.
          <year>2014</year>
          .
          <volume>6949294</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref24">
        <mixed-citation>
          24.
          <string-name>
            <given-names>S.</given-names>
            <surname>Paira</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Agarwal</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S. S.</given-names>
            <surname>Alam</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Chandra</surname>
          </string-name>
          ,
          <article-title>Doubly inserted sort: A partially insertion based dual scanned sorting algorithm</article-title>
          ,
          <source>Emerging Research in Computing, Information, Communication and Applications</source>
          , Springer, pp.
          <fpage>11</fpage>
          -
          <lpage>19</lpage>
          (
          <year>2015</year>
          ).
          <source>doi:10.1007/978-81-322-2550-8 2.</source>
        </mixed-citation>
      </ref>
      <ref id="ref25">
        <mixed-citation>
          25.
          <string-name>
            <given-names>A. A.</given-names>
            <surname>Papernov</surname>
          </string-name>
          and
          <string-name>
            <given-names>G. V.</given-names>
            <surname>Stasevich</surname>
          </string-name>
          .
          <article-title>A Method of Information Sorting in Computer Memories</article-title>
          . Problems of Information Transmission.
          <volume>1</volume>
          (
          <issue>3</issue>
          ):
          <fpage>63</fpage>
          -
          <lpage>75</lpage>
          (
          <year>1965</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref26">
        <mixed-citation>
          26.
          <string-name>
            <given-names>V. R.</given-names>
            <surname>Pratt</surname>
          </string-name>
          .
          <article-title>Shellsort and Sorting Networks (Outstanding Dissertations in the Computer Sciences)</article-title>
          .
          <source>Garland</source>
          (
          <year>1979</year>
          ).
          <source>ISBN 978-0-8240-4406-0.</source>
        </mixed-citation>
      </ref>
      <ref id="ref27">
        <mixed-citation>
          27.
          <string-name>
            <given-names>B. R.</given-names>
            <surname>Preiss</surname>
          </string-name>
          ,
          <article-title>Data Structures and Algorithms with Object-oriented Design Patterns in C++</article-title>
          , John Wiley &amp; Sons,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref28">
        <mixed-citation>
          28.
          <string-name>
            <surname>Robert</surname>
            <given-names>Sedgewick</given-names>
          </string-name>
          ,
          <article-title>The analysis of Quicksort programs</article-title>
          ,
          <source>Acta Inform</source>
          . (ISSN:
          <fpage>0001</fpage>
          -
          <lpage>5903</lpage>
          )
          <issue>7</issue>
          (
          <issue>4</issue>
          ) (
          <year>1977</year>
          )
          <fpage>327</fpage>
          -
          <lpage>355</lpage>
          . Available on http://dx.doi.org/10. 1007/BF00289467.
        </mixed-citation>
      </ref>
      <ref id="ref29">
        <mixed-citation>
          29.
          <string-name>
            <surname>Robert</surname>
            <given-names>Sedgewick</given-names>
          </string-name>
          ,
          <article-title>Implementing Quicksort programs</article-title>
          ,
          <source>Commun. ACM (ISSN: 00010782)</source>
          <volume>21</volume>
          (
          <issue>10</issue>
          ) (
          <year>1978</year>
          )
          <fpage>847</fpage>
          -
          <lpage>857</lpage>
          . http://dx.doi.org/10.1145/359619.359631.
        </mixed-citation>
      </ref>
      <ref id="ref30">
        <mixed-citation>
          30.
          <string-name>
            <given-names>R.</given-names>
            <surname>Sedgewick</surname>
          </string-name>
          .
          <article-title>A New Upper Bound for Shellsort</article-title>
          .
          <source>Journal of Algorithms</source>
          .
          <volume>7</volume>
          (
          <issue>2</issue>
          ):
          <fpage>159</fpage>
          -
          <lpage>173</lpage>
          (
          <year>1986</year>
          ). doi:
          <volume>10</volume>
          .1016/
          <fpage>0196</fpage>
          -
          <lpage>6774</lpage>
          (
          <issue>86</issue>
          )
          <fpage>90001</fpage>
          -
          <lpage>5</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref31">
        <mixed-citation>
          31.
          <string-name>
            <surname>D. L. Shell</surname>
            ,
            <given-names>A</given-names>
          </string-name>
          <string-name>
            <surname>High-Speed Sorting Procedure</surname>
          </string-name>
          .
          <source>Communications of the ACM</source>
          .
          <volume>2</volume>
          (
          <issue>7</issue>
          ):
          <fpage>30</fpage>
          -
          <lpage>32</lpage>
          (
          <year>1959</year>
          ) doi:10.1145/368370.368387.
        </mixed-citation>
      </ref>
      <ref id="ref32">
        <mixed-citation>
          32. T. SinghSodhi, S. Kaur and
          <string-name>
            <given-names>S.</given-names>
            <surname>Kaur</surname>
          </string-name>
          ,
          <article-title>Enhanced insertion sort algorithm</article-title>
          ,
          <source>Int. J. Comput. Appl</source>
          .
          <volume>64</volume>
          (
          <issue>21</issue>
          ) (
          <year>2013</year>
          )
          <fpage>35</fpage>
          -
          <lpage>39</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref33">
        <mixed-citation>
          33.
          <string-name>
            <given-names>R.</given-names>
            <surname>Srivastava</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Tiwari</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Singh</surname>
          </string-name>
          ,
          <article-title>Bidirectional expansion - Insertion algorithm for sorting</article-title>
          , Second International Conference on Emerging Trends in Engineering and Technology,
          <string-name>
            <surname>ICETET</surname>
          </string-name>
          , ISBN:
          <volume>9780769538846</volume>
          , pp.
          <fpage>59</fpage>
          -
          <lpage>62</lpage>
          (
          <year>2009</year>
          ). http://dx.doi.org/10.1109/ICETET.
          <year>2009</year>
          .
          <volume>48</volume>
          .
        </mixed-citation>
      </ref>
      <ref id="ref34">
        <mixed-citation>34. G. van den Hoven. Binary Merge Sort. https://docs.google.com/ le/d/0B8KIVXAaaGiYzcta0pFUXJnNG8/edit</mixed-citation>
      </ref>
      <ref id="ref35">
        <mixed-citation>
          35.
          <string-name>
            <given-names>S.</given-names>
            <surname>Wild</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. E.</given-names>
            <surname>Nebel</surname>
          </string-name>
          , R. Neininger,
          <article-title>Average case and distributional analysis of dual-pivot quicksort</article-title>
          ,
          <source>ACM Trans. Algorithms</source>
          ,
          <volume>11</volume>
          (
          <issue>3</issue>
          )
          <fpage>22</fpage>
          (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>