<s>
Flashsort	B-Algorithm
is	O
a	O
distribution	O
sorting	O
algorithm	O
showing	O
linear	O
computational	O
complexity	O
for	O
uniformly	O
distributed	O
data	O
sets	O
and	O
relatively	O
little	O
additional	O
memory	O
requirement	O
.	O
</s>
<s>
Flashsort	B-Algorithm
is	O
an	O
efficient	O
in-place	B-Algorithm
implementation	O
of	O
histogram	B-Algorithm
sort	I-Algorithm
,	O
itself	O
a	O
type	O
of	O
bucket	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
Convert	O
the	O
counts	O
of	O
elements	O
in	O
each	O
bucket	O
to	O
a	O
prefix	B-Application
sum	I-Application
,	O
where	O
is	O
the	O
number	O
of	O
elements	O
in	O
bucket	O
or	O
less	O
.	O
</s>
<s>
Sort	O
each	O
bucket	O
using	O
insertion	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
Steps	O
13	O
and	O
6	O
are	O
common	O
to	O
any	O
bucket	B-Algorithm
sort	I-Algorithm
,	O
and	O
can	O
be	O
improved	O
using	O
techniques	O
generic	O
to	O
bucket	B-Algorithm
sorts	I-Algorithm
.	O
</s>
<s>
While	O
the	O
basic	O
algorithm	O
is	O
a	O
linear	O
interpolation	B-Algorithm
sort	I-Algorithm
,	O
if	O
the	O
input	O
distribution	O
is	O
known	O
to	O
be	O
non-uniform	O
,	O
a	O
non-linear	O
division	O
will	O
more	O
closely	O
approximate	O
this	O
ideal	O
.	O
</s>
<s>
What	O
distinguishes	O
flash	O
sort	O
is	O
step	O
5	O
:	O
an	O
efficient	O
in-place	B-Algorithm
algorithm	I-Algorithm
for	O
collecting	O
the	O
elements	O
of	O
each	O
bucket	O
together	O
in	O
the	O
correct	O
relative	O
order	O
using	O
only	O
words	O
of	O
additional	O
memory	O
.	O
</s>
<s>
The	O
Flashsort	B-Algorithm
rearrangement	O
phase	O
operates	O
in	O
cycles	B-Algorithm
.	O
</s>
<s>
We	O
maintain	O
the	O
loop	B-Application
invariant	I-Application
that	O
each	O
bucket	O
is	O
divided	O
by	O
into	O
an	O
unclassified	O
prefix	O
(	O
for	O
have	O
yet	O
to	O
be	O
moved	O
to	O
their	O
target	O
buckets	O
)	O
and	O
a	O
classified	O
suffix	O
(	O
for	O
are	O
all	O
in	O
the	O
correct	O
bucket	O
and	O
will	O
not	O
be	O
moved	O
again	O
)	O
.	O
</s>
<s>
By	O
the	O
loop	B-Application
invariant	I-Application
,	O
it	O
is	O
classified	O
if	O
,	O
and	O
unclassified	O
if	O
is	O
outside	O
that	O
range	O
.	O
</s>
<s>
Incorporating	O
this	O
,	O
the	O
flashsort	B-Algorithm
distribution	O
algorithm	O
begins	O
with	O
as	O
described	O
above	O
and	O
.	O
</s>
<s>
While	O
saving	O
memory	O
,	O
Flashsort	B-Algorithm
has	O
the	O
disadvantage	O
that	O
it	O
recomputes	O
the	O
bucket	O
for	O
many	O
already-classified	O
elements	O
.	O
</s>
<s>
This	O
is	O
already	O
done	O
twice	O
per	O
element	O
(	O
once	O
during	O
the	O
bucket-counting	O
phase	O
and	O
a	O
second	O
time	O
when	O
moving	O
each	O
element	O
)	O
,	O
but	O
searching	B-Application
for	O
the	O
first	O
unclassified	O
element	O
requires	O
a	O
third	O
computation	O
for	O
most	O
elements	O
.	O
</s>
<s>
However	O
,	O
this	O
memory	O
efficiency	O
comes	O
with	O
the	O
disadvantage	O
that	O
the	O
array	O
is	O
accessed	O
randomly	O
,	O
so	O
cannot	O
take	O
advantage	O
of	O
a	O
data	B-General_Concept
cache	I-General_Concept
smaller	O
than	O
the	O
whole	O
array	O
.	O
</s>
<s>
As	O
with	O
all	O
bucket	B-Algorithm
sorts	I-Algorithm
,	O
performance	O
depends	O
critically	O
on	O
the	O
balance	O
of	O
the	O
buckets	O
.	O
</s>
<s>
If	O
the	O
number	O
of	O
buckets	O
is	O
linear	O
in	O
the	O
input	O
size	O
,	O
each	O
bucket	O
has	O
a	O
constant	O
size	O
,	O
so	O
sorting	O
a	O
single	O
bucket	O
with	O
an	O
algorithm	O
like	O
insertion	B-Algorithm
sort	I-Algorithm
has	O
complexity	O
.	O
</s>
<s>
The	O
running	O
time	O
of	O
the	O
final	O
insertion	B-Algorithm
sorts	I-Algorithm
is	O
therefore	O
.	O
</s>
<s>
Choosing	O
a	O
value	O
for	O
,	O
the	O
number	O
of	O
buckets	O
,	O
trades	O
off	O
time	O
spent	O
classifying	O
elements	O
(	O
high	O
)	O
and	O
time	O
spent	O
in	O
the	O
final	O
insertion	B-Algorithm
sort	I-Algorithm
step	O
(	O
low	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
is	O
chosen	O
proportional	O
to	O
,	O
then	O
the	O
running	O
time	O
of	O
the	O
final	O
insertion	B-Algorithm
sorts	I-Algorithm
is	O
therefore	O
.	O
</s>
<s>
Variations	O
of	O
the	O
algorithm	O
improve	O
worst-case	O
performance	O
by	O
using	O
better-performing	O
sorts	O
such	O
as	O
quicksort	B-Algorithm
or	O
recursive	O
flashsort	B-Algorithm
on	O
buckets	O
which	O
exceed	O
a	O
certain	O
size	O
limit	O
.	O
</s>
<s>
For	O
with	O
uniformly	O
distributed	O
random	O
data	O
,	O
flashsort	B-Algorithm
is	O
faster	O
than	O
heapsort	B-Application
for	O
all	O
and	O
faster	O
than	O
quicksort	B-Algorithm
for	O
.	O
</s>
<s>
It	O
becomes	O
about	O
twice	O
as	O
fast	O
as	O
quicksort	B-Algorithm
at	O
.	O
</s>
<s>
Note	O
that	O
these	O
measurements	O
were	O
taken	O
in	O
the	O
late	O
1990s	O
,	O
when	O
memory	B-General_Concept
hierarchies	I-General_Concept
were	O
much	O
less	O
dependent	O
on	O
cacheing	O
.	O
</s>
<s>
Due	O
to	O
the	O
in	O
situ	O
permutation	O
that	O
flashsort	B-Algorithm
performs	O
in	O
its	O
classification	O
process	O
,	O
flashsort	B-Algorithm
is	O
not	O
stable	O
.	O
</s>
