<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
quickselect	B-Algorithm
is	O
a	O
selection	B-Algorithm
algorithm	I-Algorithm
to	O
find	O
the	O
kth	O
smallest	O
element	O
in	O
an	O
unordered	O
list	O
,	O
also	O
known	O
as	O
the	O
kth	O
order	O
statistic	O
.	O
</s>
<s>
Like	O
the	O
related	O
quicksort	B-Algorithm
sorting	O
algorithm	O
,	O
it	O
was	O
developed	O
by	O
Tony	O
Hoare	O
,	O
and	O
thus	O
is	O
also	O
known	O
as	O
Hoare	O
's	O
selection	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
Like	O
quicksort	B-Algorithm
,	O
it	O
is	O
efficient	O
in	O
practice	O
and	O
has	O
good	O
average-case	O
performance	O
,	O
but	O
has	O
poor	O
worst-case	O
performance	O
.	O
</s>
<s>
Quickselect	B-Algorithm
and	O
its	O
variants	O
are	O
the	O
selection	B-Algorithm
algorithms	I-Algorithm
most	O
often	O
used	O
in	O
efficient	O
real-world	O
implementations	O
.	O
</s>
<s>
Quickselect	B-Algorithm
uses	O
the	O
same	O
overall	O
approach	O
as	O
quicksort	B-Algorithm
,	O
choosing	O
one	O
element	O
as	O
a	O
pivot	O
and	O
partitioning	O
the	O
data	O
in	O
two	O
based	O
on	O
the	O
pivot	O
,	O
accordingly	O
as	O
less	O
than	O
or	O
greater	O
than	O
the	O
pivot	O
.	O
</s>
<s>
However	O
,	O
instead	O
of	O
recursing	O
into	O
both	O
sides	O
,	O
as	O
in	O
quicksort	B-Algorithm
,	O
quickselect	B-Algorithm
only	O
recurses	O
into	O
one	O
side	O
–	O
the	O
side	O
with	O
the	O
element	O
it	O
is	O
searching	O
for	O
.	O
</s>
<s>
As	O
with	O
quicksort	B-Algorithm
,	O
quickselect	B-Algorithm
is	O
generally	O
implemented	O
as	O
an	O
in-place	B-Algorithm
algorithm	I-Algorithm
,	O
and	O
beyond	O
selecting	O
the	O
th	O
element	O
,	O
it	O
also	O
partially	O
sorts	O
the	O
data	O
.	O
</s>
<s>
See	O
selection	B-Algorithm
algorithm	I-Algorithm
for	O
further	O
discussion	O
of	O
the	O
connection	O
with	O
sorting	O
.	O
</s>
<s>
In	O
quicksort	B-Algorithm
,	O
there	O
is	O
a	O
subprocedure	O
called	O
partition	O
that	O
can	O
,	O
in	O
linear	O
time	O
,	O
group	O
a	O
list	O
(	O
ranging	O
from	O
indices	O
left	O
to	O
right	O
)	O
into	O
two	O
parts	O
:	O
those	O
less	O
than	O
a	O
certain	O
element	O
,	O
and	O
those	O
greater	O
than	O
or	O
equal	O
to	O
the	O
element	O
.	O
</s>
<s>
In	O
quicksort	B-Algorithm
,	O
we	O
recursively	O
sort	O
both	O
branches	O
,	O
leading	O
to	O
best-case	O
time	O
.	O
</s>
<s>
Therefore	O
,	O
a	O
single	O
recursive	O
call	O
locates	O
the	O
desired	O
element	O
in	O
the	O
correct	O
partition	O
,	O
and	O
we	O
build	O
upon	O
this	O
for	O
quickselect	B-Algorithm
:	O
</s>
<s>
Note	O
the	O
resemblance	O
to	O
quicksort	B-Algorithm
:	O
just	O
as	O
the	O
minimum-based	O
selection	B-Algorithm
algorithm	I-Algorithm
is	O
a	O
partial	O
selection	O
sort	O
,	O
this	O
is	O
a	O
partial	O
quicksort	B-Algorithm
,	O
generating	O
and	O
partitioning	O
only	O
of	O
its	O
partitions	O
.	O
</s>
<s>
This	O
simple	O
procedure	O
has	O
expected	O
linear	O
performance	O
,	O
and	O
,	O
like	O
quicksort	B-Algorithm
,	O
has	O
quite	O
good	O
performance	O
in	O
practice	O
.	O
</s>
<s>
It	O
is	O
also	O
an	O
in-place	B-Algorithm
algorithm	I-Algorithm
,	O
requiring	O
only	O
constant	O
memory	O
overhead	O
if	O
tail	B-Language
call	I-Language
optimization	I-Language
is	O
available	O
,	O
or	O
if	O
eliminating	O
the	O
tail	B-Language
recursion	I-Language
with	O
a	O
loop	O
:	O
</s>
<s>
Like	O
quicksort	B-Algorithm
,	O
quickselect	B-Algorithm
has	O
good	O
average	O
performance	O
,	O
but	O
is	O
sensitive	O
to	O
the	O
pivot	O
that	O
is	O
chosen	O
.	O
</s>
<s>
Deterministically	O
,	O
one	O
can	O
use	O
median-of-3	O
pivot	O
strategy	O
(	O
as	O
in	O
the	O
quicksort	B-Algorithm
)	O
,	O
which	O
yields	O
linear	O
performance	O
on	O
partially	O
sorted	O
data	O
,	O
as	O
is	O
common	O
in	O
the	O
real	O
world	O
.	O
</s>
<s>
However	O
,	O
contrived	O
sequences	O
can	O
still	O
cause	O
worst-case	O
complexity	O
;	O
David	O
Musser	O
describes	O
a	O
"	O
median-of-3	O
killer	O
"	O
sequence	O
that	O
allows	O
an	O
attack	O
against	O
that	O
strategy	O
,	O
which	O
was	O
one	O
motivation	O
for	O
his	O
introselect	B-Algorithm
algorithm	O
.	O
</s>
<s>
One	O
can	O
assure	O
linear	O
performance	O
even	O
in	O
the	O
worst	O
case	O
by	O
using	O
a	O
more	O
sophisticated	O
pivot	O
strategy	O
;	O
this	O
is	O
done	O
in	O
the	O
median	B-Algorithm
of	I-Algorithm
medians	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
One	O
can	O
combine	O
basic	O
quickselect	B-Algorithm
with	O
median	B-Algorithm
of	I-Algorithm
medians	I-Algorithm
as	O
fallback	O
to	O
get	O
both	O
fast	O
average	O
case	O
performance	O
and	O
linear	O
worst-case	O
performance	O
;	O
this	O
is	O
done	O
in	O
introselect	B-Algorithm
.	O
</s>
<s>
The	O
constant	O
can	O
be	O
improved	O
to	O
3/2	O
by	O
a	O
more	O
complicated	O
pivot	O
strategy	O
,	O
yielding	O
the	O
Floyd	B-Algorithm
–	I-Algorithm
Rivest	I-Algorithm
algorithm	I-Algorithm
,	O
which	O
has	O
average	O
complexity	O
of	O
for	O
median	O
,	O
with	O
other	O
k	O
being	O
faster	O
.	O
</s>
