<s>
Quicksort	B-Algorithm
is	O
an	O
efficient	O
,	O
general-purpose	O
sorting	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Quicksort	B-Algorithm
was	O
developed	O
by	O
British	O
computer	O
scientist	O
Tony	O
Hoare	O
in	O
1959	O
and	O
published	O
in	O
1961	O
.	O
</s>
<s>
It	O
is	O
still	O
a	O
commonly	O
used	O
algorithm	O
for	O
sorting	B-Algorithm
.	O
</s>
<s>
Overall	O
,	O
it	O
is	O
slightly	O
faster	O
than	O
merge	B-Algorithm
sort	I-Algorithm
and	O
heapsort	B-Application
for	O
randomized	O
data	O
,	O
particularly	O
on	O
larger	O
distributions	O
.	O
</s>
<s>
Quicksort	B-Algorithm
is	O
a	O
divide-and-conquer	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
For	O
this	O
reason	O
,	O
it	O
is	O
sometimes	O
called	O
partition-exchange	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
This	O
can	O
be	O
done	O
in-place	B-Algorithm
,	O
requiring	O
small	O
additional	O
amounts	O
of	O
memory	O
to	O
perform	O
the	O
sorting	B-Algorithm
.	O
</s>
<s>
Quicksort	B-Algorithm
is	O
a	O
comparison	B-Algorithm
sort	I-Algorithm
,	O
meaning	O
that	O
it	O
can	O
sort	O
items	O
of	O
any	O
type	O
for	O
which	O
a	O
"	O
less-than	O
"	O
relation	O
(	O
formally	O
,	O
a	O
total	O
order	O
)	O
is	O
defined	O
.	O
</s>
<s>
Most	O
implementations	O
of	O
quicksort	B-Algorithm
are	O
not	O
stable	O
,	O
meaning	O
that	O
the	O
relative	O
order	O
of	O
equal	O
sort	O
items	O
is	O
not	O
preserved	O
.	O
</s>
<s>
Mathematical	B-General_Concept
analysis	I-General_Concept
of	O
quicksort	B-Algorithm
shows	O
that	O
,	O
on	B-General_Concept
average	I-General_Concept
,	O
the	O
algorithm	O
takes	O
comparisons	O
to	O
sort	O
n	O
items	O
.	O
</s>
<s>
In	O
the	O
worst	B-General_Concept
case	I-General_Concept
,	O
it	O
makes	O
comparisons	O
.	O
</s>
<s>
The	O
quicksort	B-Algorithm
algorithm	O
was	O
developed	O
in	O
1959	O
by	O
Tony	O
Hoare	O
while	O
he	O
was	O
a	O
visiting	O
student	O
at	O
Moscow	O
State	O
University	O
.	O
</s>
<s>
At	O
that	O
time	O
,	O
Hoare	O
was	O
working	O
on	O
a	O
machine	B-Application
translation	I-Application
project	O
for	O
the	O
National	O
Physical	O
Laboratory	O
.	O
</s>
<s>
As	O
a	O
part	O
of	O
the	O
translation	O
process	O
,	O
he	O
needed	O
to	O
sort	O
the	O
words	O
in	O
Russian	O
sentences	O
before	O
looking	O
them	O
up	O
in	O
a	O
Russian-English	O
dictionary	O
,	O
which	O
was	O
in	O
alphabetical	O
order	O
on	O
magnetic	B-Architecture
tape	I-Architecture
.	O
</s>
<s>
After	O
recognizing	O
that	O
his	O
first	O
idea	O
,	O
insertion	B-Algorithm
sort	I-Algorithm
,	O
would	O
be	O
slow	O
,	O
he	O
came	O
up	O
with	O
a	O
new	O
idea	O
.	O
</s>
<s>
He	O
wrote	O
the	O
partition	O
part	O
in	O
Mercury	B-Language
Autocode	I-Language
but	O
had	O
trouble	O
dealing	O
with	O
the	O
list	O
of	O
unsorted	O
segments	O
.	O
</s>
<s>
On	O
return	O
to	O
England	O
,	O
he	O
was	O
asked	O
to	O
write	O
code	O
for	O
Shellsort	B-Algorithm
.	O
</s>
<s>
Later	O
,	O
Hoare	O
learned	O
about	O
ALGOL	B-Language
and	O
its	O
ability	O
to	O
do	O
recursion	O
that	O
enabled	O
him	O
to	O
publish	O
the	O
code	O
in	O
Communications	O
of	O
the	O
Association	O
for	O
Computing	O
Machinery	O
,	O
the	O
premier	O
computer	O
science	O
journal	O
of	O
the	O
time	O
.	O
</s>
<s>
Quicksort	B-Algorithm
gained	O
widespread	O
adoption	O
,	O
appearing	O
,	O
for	O
example	O
,	O
in	O
Unix	B-Application
as	O
the	O
default	O
library	O
sort	O
subroutine	O
.	O
</s>
<s>
Hence	O
,	O
it	O
lent	O
its	O
name	O
to	O
the	B-Language
C	I-Language
standard	I-Language
library	I-Language
subroutine	O
and	O
in	O
the	O
reference	O
implementation	O
of	O
Java	B-Language
.	O
</s>
<s>
Robert	O
Sedgewick	O
's	O
PhD	O
thesis	O
in	O
1975	O
is	O
considered	O
a	O
milestone	O
in	O
the	O
study	O
of	O
Quicksort	B-Algorithm
where	O
he	O
resolved	O
many	O
open	O
problems	O
related	O
to	O
the	O
analysis	O
of	O
various	O
pivot	O
selection	O
schemes	O
including	O
Samplesort	B-Operating_System
,	O
adaptive	O
partitioning	O
by	O
Van	O
Emden	O
as	O
well	O
as	O
derivation	O
of	O
expected	O
number	O
of	O
comparisons	O
and	O
swaps	O
.	O
</s>
<s>
Bentley	O
described	O
Quicksort	B-Algorithm
as	O
the	O
"	O
most	O
beautiful	O
code	O
I	O
had	O
ever	O
written	O
"	O
in	O
the	O
same	O
essay	O
.	O
</s>
<s>
Lomuto	O
's	O
partition	O
scheme	O
was	O
also	O
popularized	O
by	O
the	O
textbook	O
Introduction	O
to	O
Algorithms	O
although	O
it	O
is	O
inferior	O
to	O
Hoare	O
's	O
scheme	O
because	O
it	O
does	O
three	O
times	O
more	O
swaps	O
on	B-General_Concept
average	I-General_Concept
and	O
degrades	O
to	O
runtime	O
when	O
all	O
elements	O
are	O
equal	O
.	O
</s>
<s>
McIlroy	O
would	O
further	O
produce	O
an	O
AntiQuicksort	O
(	O
)	O
function	O
in	O
1998	O
,	O
which	O
consistently	O
drives	O
even	O
his	O
1993	O
variant	O
of	O
Quicksort	B-Algorithm
into	O
quadratic	O
behavior	O
by	O
producing	O
adversarial	O
data	O
on-the-fly	O
.	O
</s>
<s>
Quicksort	B-Algorithm
is	O
a	O
type	O
of	O
divide	B-Algorithm
and	I-Algorithm
conquer	I-Algorithm
algorithm	I-Algorithm
for	O
sorting	B-Algorithm
an	O
array	O
,	O
based	O
on	O
a	O
partitioning	O
routine	O
;	O
the	O
details	O
of	O
this	O
partitioning	O
can	O
vary	O
somewhat	O
,	O
so	O
that	O
quicksort	B-Algorithm
is	O
really	O
a	O
family	O
of	O
closely	O
related	O
algorithms	O
.	O
</s>
<s>
After	O
applying	O
this	O
partition	O
,	O
quicksort	B-Algorithm
then	O
recursively	O
sorts	O
the	O
sub-ranges	O
,	O
possibly	O
after	O
excluding	O
from	O
them	O
an	O
element	O
at	O
the	O
point	O
of	O
division	O
that	O
is	O
at	O
this	O
point	O
known	O
to	O
be	O
already	O
in	O
its	O
final	O
location	O
.	O
</s>
<s>
Due	O
to	O
its	O
recursive	O
nature	O
,	O
quicksort	B-Algorithm
(	O
like	O
the	O
partition	O
routine	O
)	O
has	O
to	O
be	O
formulated	O
so	O
as	O
to	O
be	O
callable	O
for	O
a	O
range	O
within	O
a	O
larger	O
array	O
,	O
even	O
if	O
the	O
ultimate	O
goal	O
is	O
to	O
sort	O
a	O
complete	O
array	O
.	O
</s>
<s>
The	O
steps	O
for	O
in-place	B-Algorithm
quicksort	B-Algorithm
are	O
:	O
</s>
<s>
Possibly	O
for	O
other	O
very	O
short	O
lengths	O
a	O
special-purpose	O
sorting	B-Algorithm
method	O
is	O
applied	O
and	O
the	O
remainder	O
of	O
these	O
steps	O
skipped	O
.	O
</s>
<s>
Since	O
at	O
least	O
one	O
instance	O
of	O
the	O
pivot	O
is	O
present	O
,	O
most	O
partition	O
routines	O
ensure	O
that	O
the	O
value	O
that	O
ends	O
up	O
at	O
the	O
point	O
of	O
division	O
is	O
equal	O
to	O
the	O
pivot	O
,	O
and	O
is	O
now	O
in	O
its	O
final	O
position	O
(	O
but	O
termination	O
of	O
quicksort	B-Algorithm
does	O
not	O
depend	O
on	O
this	O
,	O
as	O
long	O
as	O
sub-ranges	O
strictly	O
smaller	O
than	O
the	O
original	O
are	O
produced	O
)	O
.	O
</s>
<s>
Recursively	O
apply	O
the	O
quicksort	B-Algorithm
to	O
the	O
sub-range	O
up	O
to	O
the	O
point	O
of	O
division	O
and	O
to	O
the	O
sub-range	O
after	O
it	O
,	O
possibly	O
excluding	O
from	O
both	O
ranges	O
the	O
element	O
equal	O
to	O
the	O
pivot	O
at	O
the	O
point	O
of	O
division	O
.	O
</s>
<s>
In	O
discussing	O
the	O
efficiency	O
of	O
quicksort	B-Algorithm
,	O
it	O
is	O
therefore	O
necessary	O
to	O
specify	O
these	O
choices	O
first	O
.	O
</s>
<s>
The	O
complexity	O
of	O
Quicksort	B-Algorithm
with	O
this	O
scheme	O
degrades	O
to	O
when	O
the	O
array	O
is	O
already	O
in	O
order	O
,	O
due	O
to	O
the	O
partition	O
being	O
the	O
worst	O
possible	O
one	O
.	O
</s>
<s>
There	O
have	O
been	O
various	O
variants	O
proposed	O
to	O
boost	O
performance	O
including	O
various	O
ways	O
to	O
select	O
the	O
pivot	O
,	O
deal	O
with	O
equal	O
elements	O
,	O
use	O
other	O
sorting	B-Algorithm
algorithms	I-Algorithm
such	O
as	O
insertion	B-Algorithm
sort	I-Algorithm
for	O
small	O
arrays	O
,	O
and	O
so	O
on	O
.	O
</s>
<s>
In	O
pseudocode	B-Language
,	O
a	O
quicksort	B-Algorithm
that	O
sorts	O
elements	O
at	O
through	O
(	O
inclusive	O
)	O
of	O
an	O
array	O
can	O
be	O
expressed	O
as	O
:	O
</s>
<s>
Sorting	B-Algorithm
the	O
entire	O
array	O
is	O
accomplished	O
by	O
.	O
</s>
<s>
Hoare	O
therefore	O
stipulates	O
that	O
at	O
the	O
end	O
,	O
the	O
sub-range	O
containing	O
the	O
pivot	O
element	O
(	O
which	O
still	O
is	O
at	O
its	O
original	O
position	O
)	O
can	O
be	O
decreased	O
in	O
size	O
by	O
excluding	O
that	O
pivot	O
,	O
after	O
(	O
if	O
necessary	O
)	O
exchanging	O
it	O
with	O
the	O
sub-range	O
element	O
closest	O
to	O
the	O
separation	O
;	O
thus	O
,	O
termination	O
of	O
quicksort	B-Algorithm
is	O
ensured	O
.	O
</s>
<s>
However	O
,	O
using	O
an	O
inclusive	O
test	O
throughout	O
also	O
ensures	O
that	O
a	O
division	O
near	O
the	O
middle	O
is	O
found	O
when	O
all	O
elements	O
in	O
the	O
range	O
are	O
equal	O
,	O
which	O
gives	O
an	O
important	O
efficiency	O
gain	O
for	O
sorting	B-Algorithm
arrays	O
with	O
many	O
equal	O
elements	O
.	O
)	O
</s>
<s>
In	O
pseudocode	B-Language
,	O
</s>
<s>
Hoare	O
's	O
scheme	O
is	O
more	O
efficient	O
than	O
Lomuto	O
's	O
partition	O
scheme	O
because	O
it	O
does	O
three	O
times	O
fewer	O
swaps	O
on	B-General_Concept
average	I-General_Concept
.	O
</s>
<s>
Like	O
Lomuto	O
's	O
partition	O
scheme	O
,	O
Hoare	O
's	O
partitioning	O
also	O
would	O
cause	O
Quicksort	B-Algorithm
to	O
degrade	O
to	O
for	O
already	O
sorted	O
input	O
,	O
if	O
the	O
pivot	O
was	O
chosen	O
as	O
the	O
first	O
or	O
the	O
last	O
element	O
.	O
</s>
<s>
With	O
the	O
middle	O
element	O
as	O
the	O
pivot	O
,	O
however	O
,	O
sorted	O
data	O
results	O
with	O
(	O
almost	O
)	O
no	O
swaps	O
in	O
equally	O
sized	O
partitions	O
leading	O
to	O
best	B-General_Concept
case	I-General_Concept
behavior	O
of	O
Quicksort	B-Algorithm
,	O
i.e.	O
</s>
<s>
Let	O
's	O
first	O
examine	O
the	O
choice	O
of	O
recursing	O
on	O
and	O
,	O
with	O
the	O
example	O
of	O
sorting	B-Algorithm
an	O
array	O
where	O
multiple	O
identical	O
elements	O
exist	O
.	O
</s>
<s>
The	O
two	O
nuances	O
are	O
clear	O
,	O
again	O
,	O
when	O
considering	O
the	O
examples	O
of	O
sorting	B-Algorithm
an	O
array	O
where	O
multiple	O
identical	O
elements	O
exist	O
(	O
)	O
,	O
and	O
an	O
already	O
sorted	O
array	O
respectively	O
.	O
</s>
<s>
In	O
the	O
very	O
early	O
versions	O
of	O
quicksort	B-Algorithm
,	O
the	O
leftmost	O
element	O
of	O
the	O
partition	O
would	O
often	O
be	O
chosen	O
as	O
the	O
pivot	O
element	O
.	O
</s>
<s>
Unfortunately	O
,	O
this	O
causes	O
worst-case	B-General_Concept
behavior	O
on	O
already	O
sorted	O
arrays	O
,	O
which	O
is	O
a	O
rather	O
common	O
use-case	O
.	O
</s>
<s>
Selecting	O
a	O
pivot	O
element	O
is	O
also	O
complicated	O
by	O
the	O
existence	O
of	O
integer	B-Error_Name
overflow	I-Error_Name
.	O
</s>
<s>
With	O
a	O
partitioning	O
algorithm	O
such	O
as	O
the	O
Lomuto	O
partition	O
scheme	O
described	O
above	O
(	O
even	O
one	O
that	O
chooses	O
good	O
pivot	O
values	O
)	O
,	O
quicksort	B-Algorithm
exhibits	O
poor	O
performance	O
for	O
inputs	O
that	O
contain	O
many	O
repeated	O
elements	O
.	O
</s>
<s>
However	O
,	O
with	O
a	O
partitioning	O
algorithm	O
such	O
as	O
the	O
Hoare	O
partition	O
scheme	O
,	O
repeated	O
elements	O
generally	O
results	O
in	O
better	O
partitioning	O
,	O
and	O
although	O
needless	O
swaps	O
of	O
elements	O
equal	O
to	O
the	O
pivot	O
may	O
occur	O
,	O
the	O
running	O
time	O
generally	O
decreases	O
as	O
the	O
number	O
of	O
repeated	O
elements	O
increases	O
(	O
with	O
memory	B-General_Concept
cache	I-General_Concept
reducing	O
the	O
swap	O
overhead	O
)	O
.	O
</s>
<s>
In	O
the	O
case	O
where	O
all	O
elements	O
are	O
equal	O
,	O
Hoare	O
partition	O
scheme	O
needlessly	O
swaps	O
elements	O
,	O
but	O
the	O
partitioning	O
itself	O
is	O
best	B-General_Concept
case	I-General_Concept
,	O
as	O
noted	O
in	O
the	O
Hoare	O
partition	O
section	O
above	O
.	O
</s>
<s>
(	O
Bentley	O
and	O
McIlroy	O
call	O
this	O
a	O
"	O
fat	O
partition	O
"	O
and	O
it	O
was	O
already	O
implemented	O
in	O
the	O
of	O
Version	B-Operating_System
7	I-Operating_System
Unix	I-Operating_System
.	O
)	O
</s>
<s>
Consequently	O
,	O
the	O
items	O
of	O
the	O
partition	O
need	O
not	O
be	O
included	O
in	O
the	O
recursive	O
calls	O
to	O
quicksort	B-Algorithm
.	O
</s>
<s>
The	O
best	B-General_Concept
case	I-General_Concept
for	O
the	O
algorithm	O
now	O
occurs	O
when	O
all	O
elements	O
are	O
equal	O
(	O
or	O
are	O
chosen	O
from	O
a	O
small	O
set	O
of	O
elements	O
)	O
.	O
</s>
<s>
In	O
the	O
case	O
of	O
all	O
equal	O
elements	O
,	O
the	O
modified	O
quicksort	B-Algorithm
will	O
perform	O
only	O
two	O
recursive	O
calls	O
on	O
empty	O
subarrays	O
and	O
thus	O
finish	O
in	O
linear	O
time	O
(	O
assuming	O
the	O
partition	O
subroutine	O
takes	O
no	O
longer	O
than	O
linear	O
time	O
)	O
.	O
</s>
<s>
To	O
make	O
sure	O
at	O
most	O
space	O
is	O
used	O
,	O
recur	O
first	O
into	O
the	O
smaller	O
side	O
of	O
the	O
partition	O
,	O
then	O
use	O
a	O
tail	B-Language
call	I-Language
to	O
recur	O
into	O
the	O
other	O
,	O
or	O
update	O
the	O
parameters	O
to	O
no	O
longer	O
include	O
the	O
now	O
sorted	O
smaller	O
side	O
,	O
and	O
iterate	O
to	O
sort	O
the	O
larger	O
side	O
.	O
</s>
<s>
When	O
the	O
number	O
of	O
elements	O
is	O
below	O
some	O
threshold	O
(	O
perhaps	O
ten	O
elements	O
)	O
,	O
switch	O
to	O
a	O
non-recursive	O
sorting	B-Algorithm
algorithm	I-Algorithm
such	O
as	O
insertion	B-Algorithm
sort	I-Algorithm
that	O
performs	O
fewer	O
swaps	O
,	O
comparisons	O
or	O
other	O
operations	O
on	O
such	O
small	O
arrays	O
.	O
</s>
<s>
An	O
older	O
variant	O
of	O
the	O
previous	O
optimization	O
:	O
when	O
the	O
number	O
of	O
elements	O
is	O
less	O
than	O
the	O
threshold	O
,	O
simply	O
stop	O
;	O
then	O
after	O
the	O
whole	O
array	O
has	O
been	O
processed	O
,	O
perform	O
insertion	B-Algorithm
sort	I-Algorithm
on	O
it	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
insertion	B-Algorithm
sort	I-Algorithm
takes	O
time	O
to	O
finish	O
the	O
sort	O
,	O
which	O
is	O
linear	O
if	O
is	O
a	O
constant	O
.	O
</s>
<s>
Compared	O
to	O
the	O
"	O
many	O
small	O
sorts	O
"	O
optimization	O
,	O
this	O
version	O
may	O
execute	O
fewer	O
instructions	O
,	O
but	O
it	O
makes	O
suboptimal	O
use	O
of	O
the	O
cache	B-General_Concept
memories	I-General_Concept
in	O
modern	O
computers	O
.	O
</s>
<s>
Quicksort	B-Algorithm
's	O
divide-and-conquer	O
formulation	O
makes	O
it	O
amenable	O
to	O
parallelization	B-Operating_System
using	O
task	B-Operating_System
parallelism	I-Operating_System
.	O
</s>
<s>
The	O
partitioning	O
step	O
is	O
accomplished	O
through	O
the	O
use	O
of	O
a	O
parallel	B-Application
prefix	I-Application
sum	I-Application
algorithm	O
to	O
compute	O
an	O
index	O
for	O
each	O
array	O
element	O
in	O
its	O
section	O
of	O
the	O
partitioned	O
array	O
.	O
</s>
<s>
Assuming	O
an	O
ideal	O
choice	O
of	O
pivots	O
,	O
parallel	B-Algorithm
quicksort	I-Algorithm
sorts	O
an	O
array	O
of	O
size	O
in	O
work	O
in	O
time	O
using	O
additional	O
space	O
.	O
</s>
<s>
Quicksort	B-Algorithm
has	O
some	O
disadvantages	O
when	O
compared	O
to	O
alternative	O
sorting	B-Algorithm
algorithms	I-Algorithm
,	O
like	O
merge	B-Algorithm
sort	I-Algorithm
,	O
which	O
complicate	O
its	O
efficient	O
parallelization	B-Operating_System
.	O
</s>
<s>
The	O
depth	O
of	O
quicksort	B-Algorithm
's	O
divide-and-conquer	O
tree	O
directly	O
impacts	O
the	O
algorithm	O
's	O
scalability	O
,	O
and	O
this	O
depth	O
is	O
highly	O
dependent	O
on	O
the	O
algorithm	O
's	O
choice	O
of	O
pivot	O
.	O
</s>
<s>
Additionally	O
,	O
it	O
is	O
difficult	O
to	O
parallelize	O
the	O
partitioning	O
step	O
efficiently	O
in-place	B-Algorithm
.	O
</s>
<s>
Other	O
more	O
sophisticated	O
parallel	O
sorting	B-Algorithm
algorithms	I-Algorithm
can	O
achieve	O
even	O
better	O
time	O
bounds	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
1991	O
David	O
Powers	O
described	O
a	O
parallelized	O
quicksort	B-Algorithm
(	O
and	O
a	O
related	O
radix	B-Algorithm
sort	I-Algorithm
)	O
that	O
can	O
operate	O
in	O
time	O
on	O
a	O
CRCW	B-Operating_System
(	O
concurrent	O
read	O
and	O
concurrent	O
write	O
)	O
PRAM	B-Operating_System
(	O
parallel	B-Operating_System
random-access	I-Operating_System
machine	I-Operating_System
)	O
with	O
processors	O
by	O
performing	O
partitioning	O
implicitly	O
.	O
</s>
<s>
This	O
means	O
that	O
the	O
call	B-General_Concept
tree	I-General_Concept
is	O
a	O
linear	O
chain	O
of	O
nested	O
calls	O
.	O
</s>
<s>
The	O
th	O
call	O
does	O
work	O
to	O
do	O
the	O
partition	O
,	O
and	O
,	O
so	O
in	O
that	O
case	O
quicksort	B-Algorithm
takes	O
time	O
.	O
</s>
<s>
This	O
means	O
that	O
the	O
depth	O
of	O
the	O
call	B-General_Concept
tree	I-General_Concept
is	O
.	O
</s>
<s>
But	O
no	O
two	O
calls	O
at	O
the	O
same	O
level	O
of	O
the	O
call	B-General_Concept
tree	I-General_Concept
process	O
the	O
same	O
part	O
of	O
the	O
original	O
list	O
;	O
thus	O
,	O
each	O
level	O
of	O
calls	O
needs	O
only	O
time	O
all	O
together	O
(	O
each	O
call	O
has	O
some	O
constant	O
overhead	O
,	O
but	O
since	O
there	O
are	O
only	O
calls	O
at	O
each	O
level	O
,	O
this	O
is	O
subsumed	O
in	O
the	O
factor	O
)	O
.	O
</s>
<s>
To	O
sort	O
an	O
array	O
of	O
distinct	O
elements	O
,	O
quicksort	B-Algorithm
takes	O
time	O
in	O
expectation	O
,	O
averaged	O
over	O
all	O
permutations	O
of	O
elements	O
with	O
equal	O
probability	O
.	O
</s>
<s>
We	O
list	O
here	O
three	O
common	O
proofs	O
to	O
this	O
claim	O
providing	O
different	O
insights	O
into	O
quicksort	B-Algorithm
's	O
workings	O
.	O
</s>
<s>
Although	O
this	O
could	O
take	O
a	O
long	O
time	O
,	O
on	B-General_Concept
average	I-General_Concept
only	O
flips	O
are	O
required	O
,	O
and	O
the	O
chance	O
that	O
the	O
coin	O
wo	O
n't	O
get	O
heads	O
after	O
flips	O
is	O
highly	O
improbable	O
(	O
this	O
can	O
be	O
made	O
rigorous	O
using	O
Chernoff	O
bounds	O
)	O
.	O
</s>
<s>
By	O
the	O
same	O
argument	O
,	O
Quicksort	B-Algorithm
's	O
recursion	O
will	O
terminate	O
on	B-General_Concept
average	I-General_Concept
at	O
a	O
call	O
depth	O
of	O
only	O
.	O
</s>
<s>
But	O
if	O
its	O
average	O
call	O
depth	O
is	O
,	O
and	O
each	O
level	O
of	O
the	O
call	B-General_Concept
tree	I-General_Concept
processes	O
at	O
most	O
elements	O
,	O
the	O
total	O
amount	O
of	O
work	O
done	O
on	B-General_Concept
average	I-General_Concept
is	O
the	O
product	O
,	O
.	O
</s>
<s>
This	O
is	O
the	O
same	O
relation	O
as	O
for	O
insertion	B-Algorithm
sort	I-Algorithm
and	O
selection	B-Algorithm
sort	I-Algorithm
,	O
and	O
it	O
solves	O
to	O
worst	B-General_Concept
case	I-General_Concept
.	O
</s>
<s>
The	O
master	B-Algorithm
theorem	I-Algorithm
for	I-Algorithm
divide-and-conquer	I-Algorithm
recurrences	I-Algorithm
tells	O
us	O
that	O
.	O
</s>
<s>
This	O
means	O
that	O
,	O
on	B-General_Concept
average	I-General_Concept
,	O
quicksort	B-Algorithm
performs	O
only	O
about	O
39%	O
worse	O
than	O
in	O
its	O
best	B-General_Concept
case	I-General_Concept
.	O
</s>
<s>
In	O
this	O
sense	O
,	O
it	O
is	O
closer	O
to	O
the	O
best	B-General_Concept
case	I-General_Concept
than	O
the	O
worst	B-General_Concept
case	I-General_Concept
.	O
</s>
<s>
A	O
comparison	B-Algorithm
sort	I-Algorithm
cannot	O
use	O
less	O
than	O
comparisons	O
on	B-General_Concept
average	I-General_Concept
to	O
sort	O
items	O
(	O
as	O
explained	O
in	O
the	O
article	O
Comparison	B-Algorithm
sort	I-Algorithm
)	O
and	O
in	O
case	O
of	O
large	O
,	O
Stirling	O
's	O
approximation	O
yields	O
,	O
so	O
quicksort	B-Algorithm
is	O
not	O
much	O
worse	O
than	O
an	O
ideal	O
comparison	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
This	O
fast	O
average	O
runtime	O
is	O
another	O
reason	O
for	O
quicksort	B-Algorithm
's	O
practical	O
dominance	O
over	O
other	O
sorting	B-Algorithm
algorithms	I-Algorithm
.	O
</s>
<s>
The	O
following	O
binary	B-Language
search	I-Language
tree	I-Language
(	O
BST	O
)	O
corresponds	O
to	O
each	O
execution	O
of	O
quicksort	B-Algorithm
:	O
the	O
initial	O
pivot	O
is	O
the	O
root	O
node	O
;	O
the	O
pivot	O
of	O
the	O
left	O
half	O
is	O
the	O
root	O
of	O
the	O
left	O
subtree	O
,	O
the	O
pivot	O
of	O
the	O
right	O
half	O
is	O
the	O
root	O
of	O
the	O
right	O
subtree	O
,	O
and	O
so	O
on	O
.	O
</s>
<s>
The	O
number	O
of	O
comparisons	O
of	O
the	O
execution	O
of	O
quicksort	B-Algorithm
equals	O
the	O
number	O
of	O
comparisons	O
during	O
the	O
construction	O
of	O
the	O
BST	O
by	O
a	O
sequence	O
of	O
insertions	O
.	O
</s>
<s>
So	O
,	O
the	O
average	O
number	O
of	O
comparisons	O
for	O
randomized	O
quicksort	B-Algorithm
equals	O
the	O
average	O
cost	O
of	O
constructing	O
a	O
BST	O
when	O
the	O
values	O
inserted	O
form	O
a	O
random	O
permutation	O
.	O
</s>
<s>
The	O
space	O
used	O
by	O
quicksort	B-Algorithm
depends	O
on	O
the	O
version	O
used	O
.	O
</s>
<s>
The	O
in-place	B-Algorithm
version	O
of	O
quicksort	B-Algorithm
has	O
a	O
space	O
complexity	O
of	O
,	O
even	O
in	O
the	O
worst	B-General_Concept
case	I-General_Concept
,	O
when	O
it	O
is	O
carefully	O
implemented	O
using	O
the	O
following	O
strategies	O
.	O
</s>
<s>
In-place	B-Algorithm
partitioning	O
is	O
used	O
.	O
</s>
<s>
Then	O
the	O
other	O
partition	O
is	O
sorted	O
using	O
tail	B-Language
recursion	I-Language
or	O
iteration	O
,	O
which	O
does	O
n't	O
add	O
to	O
the	O
call	B-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
Quicksort	B-Algorithm
with	O
in-place	B-Algorithm
and	O
unstable	O
partitioning	O
uses	O
only	O
constant	O
additional	O
space	O
before	O
making	O
any	O
recursive	O
call	O
.	O
</s>
<s>
Quicksort	B-Algorithm
must	O
store	O
a	O
constant	O
amount	O
of	O
information	O
for	O
each	O
nested	O
recursive	O
call	O
.	O
</s>
<s>
Since	O
the	O
best	B-General_Concept
case	I-General_Concept
makes	O
at	O
most	O
nested	O
recursive	O
calls	O
,	O
it	O
uses	O
space	O
.	O
</s>
<s>
However	O
,	O
without	O
Sedgewick	O
's	O
trick	O
to	O
limit	O
the	O
recursive	O
calls	O
,	O
in	O
the	O
worst	B-General_Concept
case	I-General_Concept
quicksort	B-Algorithm
could	O
make	O
nested	O
recursive	O
calls	O
and	O
need	O
auxiliary	O
space	O
.	O
</s>
<s>
Because	O
there	O
are	O
such	O
variables	O
in	O
every	O
stack	O
frame	O
,	O
quicksort	B-Algorithm
using	O
Sedgewick	O
's	O
trick	O
requires	O
bits	O
of	O
space	O
.	O
</s>
<s>
Another	O
,	O
less	O
common	O
,	O
not-in-place	B-Algorithm
,	O
version	O
of	O
quicksort	B-Algorithm
uses	O
space	O
for	O
working	O
storage	O
and	O
can	O
implement	O
a	O
stable	O
sort	O
.	O
</s>
<s>
Quicksort	B-Algorithm
is	O
a	O
space-optimized	O
version	O
of	O
the	O
binary	B-Algorithm
tree	I-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
Instead	O
of	O
inserting	O
items	O
sequentially	O
into	O
an	O
explicit	O
tree	O
,	O
quicksort	B-Algorithm
organizes	O
them	O
concurrently	O
into	O
a	O
tree	O
that	O
is	O
implied	O
by	O
the	O
recursive	O
calls	O
.	O
</s>
<s>
An	O
often	O
desirable	O
property	O
of	O
a	O
sorting	B-Algorithm
algorithm	I-Algorithm
is	O
stability	O
–	O
that	O
is	O
the	O
order	O
of	O
elements	O
that	O
compare	O
equal	O
is	O
not	O
changed	O
,	O
allowing	O
controlling	O
order	O
of	O
multikey	O
tables	O
(	O
e.g.	O
</s>
<s>
This	O
property	O
is	O
hard	O
to	O
maintain	O
for	O
in-place	B-Algorithm
quicksort	B-Algorithm
(	O
that	O
uses	O
only	O
constant	O
additional	O
space	O
for	O
pointers	O
and	O
buffers	O
,	O
and	O
additional	O
space	O
for	O
the	O
management	O
of	O
explicit	O
or	O
implicit	O
recursion	O
)	O
.	O
</s>
<s>
For	O
variant	O
quicksorts	B-Algorithm
involving	O
extra	O
memory	O
due	O
to	O
representations	O
using	O
pointers	O
(	O
e.g.	O
</s>
<s>
The	O
more	O
complex	O
,	O
or	O
disk-bound	O
,	O
data	O
structures	O
tend	O
to	O
increase	O
time	O
cost	O
,	O
in	O
general	O
making	O
increasing	O
use	O
of	O
virtual	O
memory	O
or	O
disk	B-Device
.	O
</s>
<s>
The	O
most	O
direct	O
competitor	O
of	O
quicksort	B-Algorithm
is	O
heapsort	B-Application
.	O
</s>
<s>
Heapsort	B-Application
's	O
running	O
time	O
is	O
,	O
but	O
heapsort	B-Application
's	O
average	O
running	O
time	O
is	O
usually	O
considered	O
slower	O
than	O
in-place	B-Algorithm
quicksort	B-Algorithm
.	O
</s>
<s>
Introsort	O
is	O
a	O
variant	O
of	O
quicksort	B-Algorithm
that	O
switches	O
to	O
heapsort	B-Application
when	O
a	O
bad	O
case	O
is	O
detected	O
to	O
avoid	O
quicksort	B-Algorithm
's	O
worst-case	B-General_Concept
running	O
time	O
.	O
</s>
<s>
Major	O
programming	O
languages	O
,	O
such	O
as	O
C++	O
(	O
in	O
the	O
GNU	O
and	O
LLVM	B-Application
implementations	O
)	O
,	O
use	O
introsort	O
.	O
</s>
<s>
Quicksort	B-Algorithm
also	O
competes	O
with	O
merge	B-Algorithm
sort	I-Algorithm
,	O
another	O
sorting	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Standard	O
merge	B-Algorithm
sort	I-Algorithm
is	O
an	O
out-of-place	O
stable	O
sort	O
,	O
unlike	O
standard	O
in-place	B-Algorithm
quicksort	B-Algorithm
and	O
heapsort	B-Application
,	O
and	O
has	O
excellent	O
worst-case	B-General_Concept
performance	I-General_Concept
.	O
</s>
<s>
The	O
main	O
disadvantage	O
of	O
mergesort	B-Algorithm
is	O
that	O
,	O
when	O
operating	O
on	O
arrays	O
,	O
efficient	O
implementations	O
require	O
auxiliary	O
space	O
,	O
whereas	O
the	O
variant	O
of	O
quicksort	B-Algorithm
with	O
in-place	B-Algorithm
partitioning	O
and	O
tail	B-Language
recursion	I-Language
uses	O
only	O
space	O
.	O
</s>
<s>
Mergesort	B-Algorithm
works	O
very	O
well	O
on	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
requiring	O
only	O
a	O
small	O
,	O
constant	O
amount	O
of	O
auxiliary	O
storage	O
.	O
</s>
<s>
Although	O
quicksort	B-Algorithm
can	O
be	O
implemented	O
as	O
a	O
stable	O
sort	O
using	O
linked	B-Data_Structure
lists	I-Data_Structure
,	O
it	O
will	O
often	O
suffer	O
from	O
poor	O
pivot	O
choices	O
without	O
random	O
access	O
.	O
</s>
<s>
Mergesort	B-Algorithm
is	O
also	O
the	O
algorithm	O
of	O
choice	O
for	O
external	B-Algorithm
sorting	I-Algorithm
of	O
very	O
large	O
data	O
sets	O
stored	O
on	O
slow-to-access	O
media	O
such	O
as	O
disk	B-Device
storage	I-Device
or	O
network-attached	B-Application
storage	I-Application
.	O
</s>
<s>
Bucket	B-Algorithm
sort	I-Algorithm
with	O
two	O
buckets	O
is	O
very	O
similar	O
to	O
quicksort	B-Algorithm
;	O
the	O
pivot	O
in	O
this	O
case	O
is	O
effectively	O
the	O
value	O
in	O
the	O
middle	O
of	O
the	O
value	O
range	O
,	O
which	O
does	O
well	O
on	B-General_Concept
average	I-General_Concept
for	O
uniformly	O
distributed	O
inputs	O
.	O
</s>
<s>
A	O
selection	B-Algorithm
algorithm	I-Algorithm
chooses	O
the	O
th	O
smallest	O
of	O
a	O
list	O
of	O
numbers	O
;	O
this	O
is	O
an	O
easier	O
problem	O
in	O
general	O
than	O
sorting	B-Algorithm
.	O
</s>
<s>
One	O
simple	O
but	O
effective	O
selection	B-Algorithm
algorithm	I-Algorithm
works	O
nearly	O
in	O
the	O
same	O
manner	O
as	O
quicksort	B-Algorithm
,	O
and	O
is	O
accordingly	O
known	O
as	O
quickselect	B-Algorithm
.	O
</s>
<s>
The	O
difference	O
is	O
that	O
instead	O
of	O
making	O
recursive	O
calls	O
on	O
both	O
sublists	O
,	O
it	O
only	O
makes	O
a	O
single	O
tail-recursive	B-Language
call	O
on	O
the	O
sublist	O
that	O
contains	O
the	O
desired	O
element	O
.	O
</s>
<s>
This	O
change	O
lowers	O
the	O
average	O
complexity	O
to	O
linear	O
or	O
time	O
,	O
which	O
is	O
optimal	O
for	O
selection	O
,	O
but	O
the	O
selection	B-Algorithm
algorithm	I-Algorithm
is	O
still	O
in	O
the	O
worst	B-General_Concept
case	I-General_Concept
.	O
</s>
<s>
A	O
variant	O
of	O
quickselect	B-Algorithm
,	O
the	O
median	B-Algorithm
of	I-Algorithm
medians	I-Algorithm
algorithm	I-Algorithm
,	O
chooses	O
pivots	O
more	O
carefully	O
,	O
ensuring	O
that	O
the	O
pivots	O
are	O
near	O
the	O
middle	O
of	O
the	O
data	O
(	O
between	O
the	O
30th	O
and	O
70th	O
percentiles	O
)	O
,	O
and	O
thus	O
has	O
guaranteed	O
linear	O
time	O
–	O
.	O
</s>
<s>
This	O
same	O
pivot	O
strategy	O
can	O
be	O
used	O
to	O
construct	O
a	O
variant	O
of	O
quicksort	B-Algorithm
(	O
median	B-Algorithm
of	I-Algorithm
medians	I-Algorithm
quicksort	B-Algorithm
)	O
with	O
time	O
.	O
</s>
<s>
More	O
abstractly	O
,	O
given	O
an	O
selection	B-Algorithm
algorithm	I-Algorithm
,	O
one	O
can	O
use	O
it	O
to	O
find	O
the	O
ideal	O
pivot	O
(	O
the	O
median	O
)	O
at	O
every	O
step	O
of	O
quicksort	B-Algorithm
and	O
thus	O
produce	O
a	O
sorting	B-Algorithm
algorithm	I-Algorithm
with	O
running	O
time	O
.	O
</s>
<s>
Practical	O
implementations	O
of	O
this	O
variant	O
are	O
considerably	O
slower	O
on	B-General_Concept
average	I-General_Concept
,	O
but	O
they	O
are	O
of	O
theoretical	O
interest	O
because	O
they	O
show	O
an	O
optimal	O
selection	B-Algorithm
algorithm	I-Algorithm
can	O
yield	O
an	O
optimal	O
sorting	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Instead	O
of	O
partitioning	O
into	O
two	O
subarrays	O
using	O
a	O
single	O
pivot	O
,	O
multi-pivot	O
quicksort	B-Algorithm
(	O
also	O
multiquicksort	O
)	O
partitions	O
its	O
input	O
into	O
some	O
number	O
of	O
subarrays	O
using	O
pivots	O
.	O
</s>
<s>
While	O
the	O
dual-pivot	O
case	O
(	O
)	O
was	O
considered	O
by	O
Sedgewick	O
and	O
others	O
already	O
in	O
the	O
mid-1970s	O
,	O
the	O
resulting	O
algorithms	O
were	O
not	O
faster	O
in	O
practice	O
than	O
the	O
"	O
classical	O
"	O
quicksort	B-Algorithm
.	O
</s>
<s>
A	O
1999	O
assessment	O
of	O
a	O
multiquicksort	O
with	O
a	O
variable	O
number	O
of	O
pivots	O
,	O
tuned	O
to	O
make	O
efficient	O
use	O
of	O
processor	B-General_Concept
caches	I-General_Concept
,	O
found	O
it	O
to	O
increase	O
the	O
instruction	O
count	O
by	O
some	O
20%	O
,	O
but	O
simulation	O
results	O
suggested	O
that	O
it	O
would	O
be	O
more	O
efficient	O
on	O
very	O
large	O
inputs	O
.	O
</s>
<s>
A	O
version	O
of	O
dual-pivot	O
quicksort	B-Algorithm
developed	O
by	O
Yaroslavskiy	O
in	O
2009	O
turned	O
out	O
to	O
be	O
fast	O
enough	O
to	O
warrant	O
implementation	O
in	O
Java	B-Language
7	O
,	O
as	O
the	O
standard	O
algorithm	O
to	O
sort	O
arrays	O
of	O
primitives	O
(	O
sorting	B-Algorithm
arrays	O
of	O
objects	O
is	O
done	O
using	O
Timsort	B-Algorithm
)	O
.	O
</s>
<s>
The	O
performance	O
benefit	O
of	O
this	O
algorithm	O
was	O
subsequently	O
found	O
to	O
be	O
mostly	O
related	O
to	O
cache	B-General_Concept
performance	O
,	O
and	O
experimental	O
results	O
indicate	O
that	O
the	O
three-pivot	O
variant	O
may	O
perform	O
even	O
better	O
on	O
modern	O
machines	O
.	O
</s>
<s>
For	O
disk	B-Device
files	O
,	O
an	O
external	B-Algorithm
sort	I-Algorithm
based	O
on	O
partitioning	O
similar	O
to	O
quicksort	B-Algorithm
is	O
possible	O
.	O
</s>
<s>
It	O
is	O
slower	O
than	O
external	B-Algorithm
merge	I-Algorithm
sort	O
,	O
but	O
does	O
n't	O
require	O
extra	O
disk	B-Device
space	O
.	O
</s>
<s>
Once	O
a	O
sub-file	O
is	O
less	O
than	O
or	O
equal	O
to	O
4	O
B	O
records	O
,	O
the	O
subfile	O
is	O
sorted	O
in-place	B-Algorithm
via	O
quicksort	B-Algorithm
and	O
written	O
.	O
</s>
<s>
The	O
average	O
number	O
of	O
passes	O
on	O
the	O
file	O
is	O
approximately	O
1	O
+	O
ln( N+1	O
)	O
/	O
( 4	O
B	O
)	O
,	O
but	O
worst	B-General_Concept
case	I-General_Concept
pattern	O
is	O
N	O
passes	O
(	O
equivalent	O
to	O
O( n^2	O
)	O
for	O
worst	B-General_Concept
case	I-General_Concept
internal	O
sort	O
)	O
.	O
</s>
<s>
This	O
algorithm	O
is	O
a	O
combination	O
of	O
radix	B-Algorithm
sort	I-Algorithm
and	O
quicksort	B-Algorithm
.	O
</s>
<s>
Given	O
we	O
sort	O
using	O
bytes	O
or	O
words	O
of	O
length	O
bits	O
,	O
the	O
best	B-General_Concept
case	I-General_Concept
is	O
and	O
the	O
worst	B-General_Concept
case	I-General_Concept
or	O
at	O
least	O
as	O
for	O
standard	O
quicksort	B-Algorithm
,	O
given	O
for	O
unique	O
keys	O
,	O
and	O
is	O
a	O
hidden	O
constant	O
in	O
all	O
standard	O
comparison	B-Algorithm
sort	I-Algorithm
algorithms	O
including	O
quicksort	B-Algorithm
.	O
</s>
<s>
This	O
is	O
a	O
kind	O
of	O
three-way	O
quicksort	B-Algorithm
in	O
which	O
the	O
middle	O
partition	O
represents	O
a	O
(	O
trivially	O
)	O
sorted	O
subarray	O
of	O
elements	O
that	O
are	O
exactly	O
equal	O
to	O
the	O
pivot	O
.	O
</s>
<s>
Also	O
developed	O
by	O
Powers	O
as	O
an	O
parallel	O
PRAM	B-Operating_System
algorithm	O
.	O
</s>
<s>
This	O
is	O
again	O
a	O
combination	O
of	O
radix	B-Algorithm
sort	I-Algorithm
and	O
quicksort	B-Algorithm
but	O
the	O
quicksort	B-Algorithm
left/right	O
partition	O
decision	O
is	O
made	O
on	O
successive	O
bits	O
of	O
the	O
key	O
,	O
and	O
is	O
thus	O
for	O
-bit	O
keys	O
.	O
</s>
<s>
All	O
comparison	B-Algorithm
sort	I-Algorithm
algorithms	O
implicitly	O
assume	O
the	O
transdichotomous	O
model	O
with	O
in	O
,	O
as	O
if	O
is	O
smaller	O
we	O
can	O
sort	O
in	O
time	O
using	O
a	O
hash	O
table	O
or	O
integer	B-Algorithm
sorting	I-Algorithm
.	O
</s>
<s>
If	O
but	O
elements	O
are	O
unique	O
within	O
bits	O
,	O
the	O
remaining	O
bits	O
will	O
not	O
be	O
looked	O
at	O
by	O
either	O
quicksort	B-Algorithm
or	O
quick	O
radix	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
Failing	O
that	O
,	O
all	O
comparison	B-Algorithm
sorting	I-Algorithm
algorithms	O
will	O
also	O
have	O
the	O
same	O
overhead	O
of	O
looking	O
through	O
relatively	O
useless	O
bits	O
but	O
quick	O
radix	B-Algorithm
sort	I-Algorithm
will	O
avoid	O
the	O
worst	B-General_Concept
case	I-General_Concept
behaviours	O
of	O
standard	O
quicksort	B-Algorithm
and	O
radix	O
quicksort	B-Algorithm
,	O
and	O
will	O
be	O
faster	O
even	O
in	O
the	O
best	B-General_Concept
case	I-General_Concept
of	O
those	O
comparison	O
algorithms	O
under	O
these	O
conditions	O
of	O
.	O
</s>
<s>
See	O
Powers	O
for	O
further	O
discussion	O
of	O
the	O
hidden	O
overheads	O
in	O
comparison	O
,	O
radix	O
and	O
parallel	O
sorting	B-Algorithm
.	O
</s>
<s>
In	O
any	O
comparison-based	O
sorting	B-Algorithm
algorithm	I-Algorithm
,	O
minimizing	O
the	O
number	O
of	O
comparisons	O
requires	O
maximizing	O
the	O
amount	O
of	O
information	O
gained	O
from	O
each	O
comparison	O
,	O
meaning	O
that	O
the	O
comparison	O
results	O
are	O
unpredictable	O
.	O
</s>
<s>
This	O
causes	O
frequent	O
branch	B-General_Concept
mispredictions	I-General_Concept
,	O
limiting	O
performance	O
.	O
</s>
<s>
BlockQuicksort	O
rearranges	O
the	O
computations	O
of	O
quicksort	B-Algorithm
to	O
convert	O
unpredictable	O
branches	O
to	O
data	B-Operating_System
dependencies	I-Operating_System
.	O
</s>
<s>
When	O
partitioning	O
,	O
the	O
input	O
is	O
divided	O
into	O
moderate-sized	O
blocks	O
(	O
which	O
fit	O
easily	O
into	O
the	O
data	B-General_Concept
cache	I-General_Concept
)	O
,	O
and	O
two	O
arrays	O
are	O
filled	O
with	O
the	O
positions	O
of	O
elements	O
to	O
swap	O
.	O
</s>
<s>
The	O
BlockQuicksort	O
technique	O
is	O
incorporated	O
into	O
LLVM	B-Application
's	O
C++	O
STL	O
implementation	O
,	O
libcxx	O
,	O
providing	O
a	O
50%	O
improvement	O
on	O
random	O
integer	O
sequences	O
.	O
</s>
<s>
Pattern-defeating	O
quicksort	B-Algorithm
(	O
pdqsort	O
)	O
,	O
a	O
version	O
of	O
introsort	O
,	O
also	O
incorporates	O
this	O
technique	O
.	O
</s>
<s>
Several	O
variants	O
of	O
quicksort	B-Algorithm
exist	O
that	O
separate	O
the	O
smallest	O
or	O
largest	O
elements	O
from	O
the	O
rest	O
of	O
the	O
input	O
.	O
</s>
<s>
Richard	O
Cole	O
and	O
David	O
C	O
.	O
Kandathil	O
,	O
in	O
2004	O
,	O
discovered	O
a	O
one-parameter	O
family	O
of	O
sorting	B-Algorithm
algorithms	I-Algorithm
,	O
called	O
partition	O
sorts	O
,	O
which	O
on	B-General_Concept
average	I-General_Concept
(	O
with	O
all	O
input	O
orderings	O
equally	O
likely	O
)	O
perform	O
at	O
most	O
comparisons	O
(	O
close	O
to	O
the	O
information	O
theoretic	O
lower	O
bound	O
)	O
and	O
operations	O
;	O
at	O
worst	O
they	O
perform	O
comparisons	O
(	O
and	O
also	O
operations	O
)	O
;	O
these	O
are	O
in-place	B-Algorithm
,	O
requiring	O
only	O
additional	O
space	O
.	O
</s>
<s>
Practical	O
efficiency	O
and	O
smaller	O
variance	O
in	O
performance	O
were	O
demonstrated	O
against	O
optimised	O
quicksorts	B-Algorithm
(	O
of	O
Sedgewick	O
and	O
Bentley-McIlroy	O
)	O
.	O
</s>
