<s>
An	O
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
is	O
an	O
efficient	O
,	O
in-place	B-Algorithm
variant	O
of	O
radix	B-Algorithm
sort	I-Algorithm
that	O
distributes	O
items	O
into	O
buckets	O
.	O
</s>
<s>
Non-comparative	O
sorting	O
algorithms	O
such	O
as	O
radix	B-Algorithm
sort	I-Algorithm
and	O
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
are	O
typically	O
used	O
to	O
sort	O
large	O
objects	O
such	O
as	O
strings	O
,	O
for	O
which	O
comparison	O
is	O
not	O
a	O
unit-time	O
operation	O
.	O
</s>
<s>
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
iterates	O
through	O
the	O
bits	O
of	O
the	O
objects	O
,	O
considering	O
several	O
bits	O
of	O
each	O
object	O
at	O
a	O
time	O
.	O
</s>
<s>
For	O
each	O
set	O
of	O
bits	O
,	O
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
makes	O
two	O
passes	O
through	O
the	O
array	O
of	O
objects	O
:	O
first	O
to	O
count	O
the	O
number	O
of	O
objects	O
that	O
will	O
fall	O
in	O
each	O
bin	O
,	O
and	O
second	O
to	O
place	O
each	O
object	O
in	O
its	O
bucket	O
.	O
</s>
<s>
With	O
some	O
optimizations	O
,	O
it	O
is	O
twice	O
as	O
fast	O
as	O
quicksort	B-Algorithm
for	O
large	O
sets	O
of	O
strings	O
.	O
</s>
<s>
The	O
name	O
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
comes	O
by	O
analogy	O
with	O
the	O
Dutch	O
national	O
flag	O
problem	O
in	O
the	O
last	O
step	O
:	O
efficiently	O
partition	O
the	O
array	O
into	O
many	O
"	O
stripes	O
"	O
.	O
</s>
<s>
In	O
contrast	O
to	O
comparison-based	B-Algorithm
sorting	I-Algorithm
algorithms	I-Algorithm
,	O
such	O
as	O
quicksort	B-Algorithm
,	O
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
is	O
based	O
on	O
directly	O
comparing	O
the	O
bytes	O
(	O
numerical	O
representation	O
)	O
of	O
the	O
underlying	O
objects	O
.	O
</s>
<s>
In-place	B-Algorithm
sorting	I-Algorithm
algorithms	I-Algorithm
,	O
including	O
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
,	O
run	O
without	O
allocating	O
a	O
significant	O
amount	O
of	O
memory	O
beyond	O
that	O
used	O
by	O
the	O
original	O
array	O
.	O
</s>
<s>
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
works	O
by	O
successively	O
dividing	O
a	O
list	O
of	O
objects	O
into	O
buckets	O
based	O
on	O
the	O
first	O
digit	O
of	O
their	O
base-N	O
representation	O
(	O
the	O
base	O
used	O
is	O
referred	O
to	O
as	O
the	O
radix	O
)	O
.	O
</s>
<s>
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
gets	O
around	O
this	O
problem	O
by	O
making	O
two	O
passes	O
through	O
the	O
array	O
.	O
</s>
<s>
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
is	O
most	O
efficient	O
with	O
a	O
radix	O
that	O
is	O
a	O
power	O
of	O
2	O
,	O
because	O
bit-shifting	O
operations	O
can	O
be	O
used	O
instead	O
of	O
expensive	O
exponentiations	O
to	O
compute	O
the	O
value	O
of	O
each	O
digit	O
.	O
</s>
<s>
When	O
sorting	O
strings	O
using	O
8	O
-	O
or	O
7-bit	O
encodings	O
such	O
as	O
ASCII	B-Protocol
,	O
it	O
is	O
typical	O
to	O
use	O
a	O
radix	O
of	O
256	O
or	O
128	O
,	O
which	O
amounts	O
to	O
sorting	O
character-by-character	O
.	O
</s>
<s>
It	O
is	O
a	O
suitable	O
algorithm	O
in	O
conjunction	O
with	O
a	O
k-way	B-Algorithm
merge	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
This	O
example	O
written	O
in	O
the	O
Python	O
programming	O
language	O
will	O
perform	O
American	B-Algorithm
flag	I-Algorithm
sort	I-Algorithm
for	O
any	O
radix	O
of	O
2	O
or	O
greater	O
.	O
</s>
