<s>
A	O
comparison	B-Algorithm
sort	I-Algorithm
is	O
a	O
type	O
of	O
sorting	B-Algorithm
algorithm	I-Algorithm
that	O
only	O
reads	O
the	O
list	O
elements	O
through	O
a	O
single	O
abstract	O
comparison	O
operation	O
(	O
often	O
a	O
"	O
less	O
than	O
or	O
equal	O
to	O
"	O
operator	O
or	O
a	O
three-way	O
comparison	O
)	O
that	O
determines	O
which	O
of	O
two	O
elements	O
should	O
occur	O
first	O
in	O
the	O
final	O
sorted	B-Algorithm
list	I-Algorithm
.	O
</s>
<s>
It	O
is	O
possible	O
that	O
both	O
a	O
≤	O
b	O
and	O
b	O
≤	O
a	O
;	O
in	O
this	O
case	O
either	O
may	O
come	O
first	O
in	O
the	O
sorted	B-Algorithm
list	I-Algorithm
.	O
</s>
<s>
A	O
metaphor	O
for	O
thinking	O
about	O
comparison	B-Algorithm
sorts	I-Algorithm
is	O
that	O
someone	O
has	O
a	O
set	O
of	O
unlabelled	O
weights	O
and	O
a	O
balance	O
scale	O
.	O
</s>
<s>
Some	O
of	O
the	O
most	O
well-known	O
comparison	B-Algorithm
sorts	I-Algorithm
include	O
:	O
</s>
<s>
There	O
are	O
fundamental	O
limits	O
on	O
the	O
performance	O
of	O
comparison	B-Algorithm
sorts	I-Algorithm
.	O
</s>
<s>
A	O
comparison	B-Algorithm
sort	I-Algorithm
must	O
have	O
an	O
average-case	O
lower	O
bound	O
of	O
Ω(n log n )	O
comparison	O
operations	O
,	O
which	O
is	O
known	O
as	O
linearithmic	O
time	O
.	O
</s>
<s>
In	O
this	O
sense	O
,	O
mergesort	B-Algorithm
,	O
heapsort	B-Application
,	O
and	O
introsort	O
are	O
asymptotically	B-General_Concept
optimal	I-General_Concept
in	O
terms	O
of	O
the	O
number	O
of	O
comparisons	O
they	O
must	O
perform	O
,	O
although	O
this	O
metric	O
neglects	O
other	O
operations	O
.	O
</s>
<s>
Comparison	B-Algorithm
sorts	I-Algorithm
may	O
run	O
faster	O
on	O
some	O
lists	O
;	O
many	O
adaptive	B-Algorithm
sorts	I-Algorithm
such	O
as	O
insertion	B-Algorithm
sort	I-Algorithm
run	O
in	O
O(n )	O
time	O
on	O
an	O
already-sorted	O
or	O
nearly-sorted	O
list	O
.	O
</s>
<s>
Real-world	O
measures	O
of	O
sorting	B-Algorithm
speed	O
may	O
need	O
to	O
take	O
into	O
account	O
the	O
ability	O
of	O
some	O
algorithms	O
to	O
optimally	O
use	O
relatively	O
fast	O
cached	O
computer	B-Architecture
memory	I-Architecture
,	O
or	O
the	O
application	O
may	O
benefit	O
from	O
sorting	B-Algorithm
methods	O
where	O
sorted	O
data	O
begins	O
to	O
appear	O
to	O
the	O
user	O
quickly	O
(	O
and	O
then	O
user	O
's	O
speed	O
of	O
reading	O
will	O
be	O
the	O
limiting	O
factor	O
)	O
as	O
opposed	O
to	O
sorting	B-Algorithm
methods	O
where	O
no	O
output	O
is	O
available	O
until	O
the	O
whole	O
list	O
is	O
sorted	O
.	O
</s>
<s>
Despite	O
these	O
limitations	O
,	O
comparison	B-Algorithm
sorts	I-Algorithm
offer	O
the	O
notable	O
practical	O
advantage	O
that	O
control	O
over	O
the	O
comparison	O
function	O
allows	O
sorting	B-Algorithm
of	O
many	O
different	O
datatypes	O
and	O
fine	O
control	O
over	O
how	O
the	O
list	O
is	O
sorted	O
.	O
</s>
<s>
For	O
example	O
,	O
reversing	O
the	O
result	O
of	O
the	O
comparison	O
function	O
allows	O
the	O
list	O
to	O
be	O
sorted	O
in	O
reverse	O
;	O
and	O
one	O
can	O
sort	O
a	O
list	O
of	O
tuples	B-Application
in	O
lexicographic	O
order	O
by	O
just	O
creating	O
a	O
comparison	O
function	O
that	O
compares	O
each	O
part	O
in	O
sequence	O
:	O
</s>
<s>
Comparison	B-Algorithm
sorts	I-Algorithm
generally	O
adapt	O
more	O
easily	O
to	O
complex	O
orders	O
such	O
as	O
the	O
order	O
of	O
floating-point	B-Algorithm
numbers	I-Algorithm
.	O
</s>
<s>
Additionally	O
,	O
once	O
a	O
comparison	O
function	O
is	O
written	O
,	O
any	O
comparison	B-Algorithm
sort	I-Algorithm
can	O
be	O
used	O
without	O
modification	O
;	O
non-comparison	O
sorts	O
typically	O
require	O
specialized	O
versions	O
for	O
each	O
datatype	O
.	O
</s>
<s>
This	O
flexibility	O
,	O
together	O
with	O
the	O
efficiency	O
of	O
the	O
above	O
comparison	B-Algorithm
sorting	I-Algorithm
algorithms	O
on	O
modern	O
computers	O
,	O
has	O
led	O
to	O
widespread	O
preference	O
for	O
comparison	B-Algorithm
sorts	I-Algorithm
in	O
most	O
practical	O
work	O
.	O
</s>
<s>
Some	O
sorting	B-Algorithm
problems	I-Algorithm
admit	O
a	O
strictly	O
faster	O
solution	O
than	O
the	O
bound	O
for	O
comparison	B-Algorithm
sorting	I-Algorithm
by	O
using	O
non-comparison	O
sorts	O
;	O
an	O
example	O
is	O
integer	B-Algorithm
sorting	I-Algorithm
,	O
where	O
all	O
keys	O
are	O
integers	O
.	O
</s>
<s>
When	O
the	O
keys	O
form	O
a	O
small	O
(	O
compared	O
to	O
)	O
range	O
,	O
counting	B-Algorithm
sort	I-Algorithm
is	O
an	O
example	O
algorithm	O
that	O
runs	O
in	O
linear	O
time	O
.	O
</s>
<s>
Other	O
integer	B-Algorithm
sorting	I-Algorithm
algorithms	O
,	O
such	O
as	O
radix	B-Algorithm
sort	I-Algorithm
,	O
are	O
not	O
asymptotically	O
faster	O
than	O
comparison	B-Algorithm
sorting	I-Algorithm
,	O
but	O
can	O
be	O
faster	O
in	O
practice	O
.	O
</s>
<s>
The	O
problem	O
of	O
sorting	B-Algorithm
pairs	I-Algorithm
of	I-Algorithm
numbers	I-Algorithm
by	I-Algorithm
their	I-Algorithm
sum	I-Algorithm
is	O
not	O
subject	O
to	O
the	O
bound	O
either	O
(	O
the	O
square	O
resulting	O
from	O
the	O
pairing	O
up	O
)	O
;	O
the	O
best	O
known	O
algorithm	O
still	O
takes	O
time	O
,	O
but	O
only	O
comparisons	O
.	O
</s>
<s>
13	O
33	O
34Takumi	O
Kasai	O
,	O
Shusaku	O
Sawato	O
,	O
Shigeki	O
Iwata	O
,	O
Thirty	O
four	O
comparisons	O
are	O
required	O
to	O
sort	O
13	O
items	O
,	O
LNCS	O
792	O
,	O
260-269	O
,	O
1994.Marcin	O
Peczarski	O
,	O
Sorting	B-Algorithm
13	O
elements	O
requires	O
34	O
comparisons	O
,	O
LNCS	O
2461	O
,	O
785	O
–	O
794	O
,	O
2002.Marcin	O
Peczarski	O
,	O
New	O
results	O
in	O
minimum-comparison	O
sorting	B-Algorithm
,	O
Algorithmica	O
40	O
(	O
2	O
)	O
,	O
133	O
–	O
145	O
,	O
2004	O
.	O
</s>
<s>
The	O
number	O
of	O
comparisons	O
that	O
a	O
comparison	B-Algorithm
sort	I-Algorithm
algorithm	O
requires	O
increases	O
in	O
proportion	O
to	O
,	O
where	O
is	O
the	O
number	O
of	O
elements	O
to	O
sort	O
.	O
</s>
<s>
The	O
sort	B-Algorithm
algorithm	I-Algorithm
must	O
gain	O
enough	O
information	O
from	O
the	O
comparisons	O
to	O
identify	O
the	O
correct	O
permutation	O
.	O
</s>
<s>
An	O
upper	O
bound	O
of	O
the	O
same	O
form	O
,	O
with	O
the	O
same	O
leading	O
term	O
as	O
the	O
bound	O
obtained	O
from	O
Stirling	O
's	O
approximation	O
,	O
follows	O
from	O
the	O
existence	O
of	O
the	O
algorithms	O
that	O
attain	O
this	O
bound	O
in	O
the	O
worst	O
case	O
,	O
like	O
merge	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
This	O
lower	O
bound	O
is	O
fairly	O
good	O
(	O
it	O
can	O
be	O
approached	O
within	O
a	O
linear	O
tolerance	O
by	O
a	O
simple	O
merge	B-Algorithm
sort	I-Algorithm
)	O
,	O
but	O
it	O
is	O
known	O
to	O
be	O
inexact	O
.	O
</s>
<s>
To	O
search	O
for	O
the	O
lower	O
bound	O
relating	O
to	O
the	O
non-achievability	O
of	O
computers	O
,	O
we	O
adopt	O
the	O
Decision	B-Application
tree	I-Application
model	I-Application
.	O
</s>
<s>
In	O
the	O
Decision	B-Application
tree	I-Application
model	I-Application
,	O
the	O
lower	O
bound	O
to	O
be	O
shown	O
is	O
the	O
lower	O
bound	O
of	O
the	O
average	O
length	O
of	O
root-to-leaf	O
paths	O
of	O
an	O
-leaf	O
binary	O
tree	O
(	O
in	O
which	O
each	O
leaf	O
corresponds	O
to	O
a	O
permutation	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
for	O
,	O
the	O
information-theoretic	O
lower	O
bound	O
for	O
the	O
average	O
case	O
is	O
approximately	O
2.58	O
,	O
while	O
the	O
average	O
lower	O
bound	O
derived	O
via	O
Decision	B-Application
tree	I-Application
model	I-Application
is	O
8/3	O
,	O
approximately	O
2.67	O
.	O
</s>
<s>
An	O
adaptive	B-Algorithm
sort	I-Algorithm
takes	O
advantage	O
of	O
this	O
"	O
presortedness	O
"	O
and	O
runs	O
more	O
quickly	O
on	O
nearly-sorted	O
inputs	O
,	O
often	O
while	O
still	O
maintaining	O
an	O
worst	O
case	O
time	O
bound	O
.	O
</s>
<s>
An	O
example	O
is	O
adaptive	B-Application
heap	I-Application
sort	I-Application
,	O
a	O
sorting	B-Algorithm
algorithm	I-Algorithm
based	O
on	O
Cartesian	B-Algorithm
trees	I-Algorithm
.	O
</s>
