<s>
A	O
sorting	B-Algorithm
algorithm	I-Algorithm
falls	O
into	O
the	O
adaptive	B-Algorithm
sort	I-Algorithm
family	O
if	O
it	O
takes	O
advantage	O
of	O
existing	O
order	O
in	O
its	O
input	O
.	O
</s>
<s>
Adaptive	O
sorting	B-Algorithm
is	O
usually	O
performed	O
by	O
modifying	O
existing	O
sorting	B-Algorithm
algorithms	I-Algorithm
.	O
</s>
<s>
Comparison-based	B-Algorithm
sorting	I-Algorithm
algorithms	I-Algorithm
have	O
traditionally	O
dealt	O
with	O
achieving	O
an	O
optimal	O
bound	O
of	O
O(n log n )	O
when	O
dealing	O
with	O
time	O
complexity	O
.	O
</s>
<s>
Adaptive	B-Algorithm
sort	I-Algorithm
takes	O
advantage	O
of	O
the	O
existing	O
order	O
of	O
the	O
input	O
to	O
try	O
to	O
achieve	O
better	O
times	O
,	O
so	O
that	O
the	O
time	O
taken	O
by	O
the	O
algorithm	O
to	O
sort	O
is	O
a	O
smoothly	O
growing	O
function	O
of	O
the	O
size	O
of	O
the	O
sequence	O
and	O
the	O
disorder	O
in	O
the	O
sequence	O
.	O
</s>
<s>
This	O
is	O
an	O
attractive	O
feature	O
for	O
a	O
sorting	B-Algorithm
algorithm	I-Algorithm
because	O
nearly	O
sorted	O
sequences	O
are	O
common	O
in	O
practice	O
.	O
</s>
<s>
Thus	O
,	O
the	O
performance	O
of	O
existing	O
sort	B-Algorithm
algorithms	I-Algorithm
can	O
be	O
improved	O
by	O
taking	O
into	O
account	O
the	O
existing	O
order	O
in	O
the	O
input	O
.	O
</s>
<s>
Note	O
that	O
most	O
worst-case	O
sorting	B-Algorithm
algorithms	I-Algorithm
that	O
do	O
optimally	O
well	O
in	O
the	O
worst-case	O
,	O
notably	O
heap	B-Application
sort	I-Application
and	O
merge	B-Algorithm
sort	I-Algorithm
,	O
do	O
not	O
take	O
existing	O
order	O
within	O
their	O
input	O
into	O
account	O
,	O
although	O
this	O
deficiency	O
is	O
easily	O
rectified	O
in	O
the	O
case	O
of	O
merge	B-Algorithm
sort	I-Algorithm
by	O
checking	O
if	O
the	O
last	O
element	O
of	O
the	O
lefthand	O
group	O
is	O
less	O
than	O
(	O
or	O
equal	O
)	O
to	O
the	O
first	O
element	O
of	O
the	O
righthand	O
group	O
,	O
in	O
which	O
case	O
a	O
merge	O
operation	O
may	O
be	O
replaced	O
by	O
simple	O
concatenation	O
–	O
a	O
modification	O
that	O
is	O
well	O
within	O
the	O
scope	O
of	O
making	O
an	O
algorithm	O
adaptive	O
.	O
</s>
<s>
A	O
classic	O
example	O
of	O
an	O
adaptive	O
sorting	B-Algorithm
algorithm	I-Algorithm
is	O
Straight	O
Insertion	O
Sort	O
.	O
</s>
<s>
In	O
this	O
sorting	B-Algorithm
algorithm	I-Algorithm
,	O
we	O
scan	O
the	O
input	O
from	O
left	O
to	O
right	O
,	O
repeatedly	O
finding	O
the	O
position	O
of	O
the	O
current	O
item	O
,	O
and	O
insert	O
it	O
into	O
an	O
array	O
of	O
previously	O
sorted	O
items	O
.	O
</s>
<s>
In	O
pseudo-code	B-Language
form	O
,	O
the	O
Straight	O
Insertion	O
Sort	B-Algorithm
algorithm	I-Algorithm
could	O
look	O
something	O
like	O
this	O
(	O
array	O
X	O
is	O
zero-based	O
)	O
:	O
</s>
<s>
The	O
performance	O
of	O
this	O
algorithm	O
can	O
be	O
described	O
in	O
terms	O
of	O
the	O
number	O
of	O
inversions	B-Algorithm
in	O
the	O
input	O
,	O
and	O
then	O
will	O
be	O
roughly	O
equal	O
to	O
,	O
where	O
is	O
the	O
number	O
of	O
Inversions	B-Algorithm
.	O
</s>
<s>
Using	O
this	O
measure	O
of	O
presortedness	O
–	O
being	O
relative	O
to	O
the	O
number	O
of	O
inversions	B-Algorithm
–	O
Straight	O
Insertion	O
Sort	O
takes	O
less	O
time	O
to	O
sort	O
the	O
closer	O
it	O
is	O
to	O
being	O
sorted	O
.	O
</s>
<s>
Other	O
examples	O
of	O
adaptive	O
sorting	B-Algorithm
algorithms	I-Algorithm
are	O
adaptive	B-Application
heap	I-Application
sort	I-Application
,	O
adaptive	O
merge	B-Algorithm
sort	I-Algorithm
,	O
patience	O
sort	O
,	O
Shellsort	B-Algorithm
,	O
smoothsort	B-Application
,	O
splaysort	B-Algorithm
,	O
Timsort	B-Algorithm
,	O
and	O
Cartesian	O
tree	O
sorting	B-Algorithm
.	O
</s>
