<s>
Library	B-Algorithm
sort	I-Algorithm
,	O
or	O
gapped	B-Algorithm
insertion	I-Algorithm
sort	I-Algorithm
is	O
a	O
sorting	B-Algorithm
algorithm	I-Algorithm
that	O
uses	O
an	O
insertion	B-Algorithm
sort	I-Algorithm
,	O
but	O
with	O
gaps	O
in	O
the	O
array	B-Data_Structure
to	O
accelerate	O
subsequent	O
insertions	O
.	O
</s>
<s>
This	O
is	O
an	O
insertion	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
This	O
is	O
the	O
basic	O
principle	O
of	O
the	O
Library	B-Algorithm
Sort	I-Algorithm
.	O
</s>
<s>
Like	O
the	O
insertion	B-Algorithm
sort	I-Algorithm
it	O
is	O
based	O
on	O
,	O
library	B-Algorithm
sort	I-Algorithm
is	O
a	O
comparison	B-Algorithm
sort	I-Algorithm
;	O
however	O
,	O
it	O
was	O
shown	O
to	O
have	O
a	O
high	O
probability	O
of	O
running	O
in	O
O(n log n )	O
time	O
(	O
comparable	O
to	O
quicksort	B-Algorithm
)	O
,	O
rather	O
than	O
an	O
insertion	B-Algorithm
sort	I-Algorithm
's	O
O(n2 )	O
.	O
</s>
<s>
Further	O
information	O
would	O
be	O
needed	O
to	O
discuss	O
how	O
the	O
efficiency	O
of	O
library	B-Algorithm
sort	I-Algorithm
compares	O
to	O
that	O
of	O
other	O
sorting	B-Algorithm
methods	O
in	O
reality	O
.	O
</s>
<s>
Compared	O
to	O
basic	O
insertion	B-Algorithm
sort	I-Algorithm
,	O
the	O
drawback	O
of	O
library	B-Algorithm
sort	I-Algorithm
is	O
that	O
it	O
requires	O
extra	O
space	O
for	O
the	O
gaps	O
.	O
</s>
<s>
In	O
the	O
paper	O
the	O
size	O
of	O
the	O
needed	O
array	B-Data_Structure
is	O
(	O
1	O
+	O
ε	O
)	O
n	O
,	O
but	O
with	O
no	O
further	O
recommendations	O
on	O
how	O
to	O
choose	O
ε	O
.	O
</s>
<s>
Another	O
drawback	O
is	O
that	O
it	O
cannot	O
be	O
run	O
as	O
an	O
online	B-Algorithm
algorithm	I-Algorithm
,	O
because	O
it	O
is	O
not	O
possible	O
to	O
randomly	O
shuffle	O
the	O
input	O
.	O
</s>
<s>
One	O
weakness	O
of	O
insertion	B-Algorithm
sort	I-Algorithm
is	O
that	O
it	O
may	O
require	O
a	O
high	O
number	O
of	O
swap	O
operations	O
and	O
be	O
costly	O
if	O
memory	O
write	O
is	O
expensive	O
.	O
</s>
<s>
Library	B-Algorithm
sort	I-Algorithm
may	O
improve	O
that	O
somewhat	O
in	O
the	O
insertion	O
step	O
,	O
as	O
fewer	O
elements	O
need	O
to	O
move	O
to	O
make	O
room	O
,	O
but	O
also	O
adds	O
an	O
extra	O
cost	O
in	O
the	O
rebalancing	O
step	O
.	O
</s>
<s>
In	O
addition	O
,	O
locality	O
of	O
reference	O
will	O
be	O
poor	O
compared	O
to	O
mergesort	B-Algorithm
,	O
as	O
each	O
insertion	O
from	O
a	O
random	O
data	O
set	O
may	O
access	O
memory	O
that	O
is	O
no	O
longer	O
in	O
cache	O
,	O
especially	O
with	O
large	O
data	O
sets	O
.	O
</s>
<s>
Let	O
us	O
say	O
we	O
have	O
an	O
array	B-Data_Structure
of	O
n	O
elements	O
.	O
</s>
<s>
Then	O
we	O
would	O
have	O
a	O
final	O
array	B-Data_Structure
of	O
size	O
(	O
1	O
+	O
ε	O
)	O
n	O
.	O
The	O
algorithm	O
works	O
in	O
log	O
n	O
rounds	O
.	O
</s>
<s>
In	O
each	O
round	O
we	O
insert	O
as	O
many	O
elements	O
as	O
there	O
are	O
in	O
the	O
final	O
array	B-Data_Structure
already	O
,	O
before	O
re-balancing	O
the	O
array	B-Data_Structure
.	O
</s>
<s>
For	O
finding	O
the	O
position	O
of	O
inserting	O
,	O
we	O
apply	O
Binary	O
Search	O
in	O
the	O
final	O
array	B-Data_Structure
and	O
then	O
swap	O
the	O
following	O
elements	O
till	O
we	O
hit	O
an	O
empty	O
space	O
.	O
</s>
<s>
Once	O
the	O
round	O
is	O
over	O
,	O
we	O
re-balance	O
the	O
final	O
array	B-Data_Structure
by	O
inserting	O
spaces	O
between	O
each	O
element	O
.	O
</s>
<s>
This	O
can	O
be	O
done	O
by	O
linearly	O
moving	O
towards	O
left	O
or	O
right	O
side	O
of	O
the	O
array	B-Data_Structure
if	O
you	O
hit	O
an	O
empty	O
space	O
in	O
the	O
middle	O
element	O
.	O
</s>
<s>
Re-Balancing	O
:	O
Inserting	O
spaces	O
between	O
each	O
pair	O
of	O
elements	O
in	O
the	O
array	B-Data_Structure
.	O
</s>
