<s>
A	O
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
is	O
a	O
variation	O
of	O
a	O
bottom-up	O
merge	B-Algorithm
sort	I-Algorithm
that	O
sorts	O
a	O
list	O
using	O
an	O
initial	O
uneven	O
distribution	O
of	O
sub-lists	O
(	O
runs	O
)	O
,	O
primarily	O
used	O
for	O
external	B-Algorithm
sorting	I-Algorithm
,	O
and	O
is	O
more	O
efficient	O
than	O
an	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
when	O
there	O
are	O
fewer	O
than	O
eight	O
external	O
working	O
files	O
(	O
such	O
as	O
a	O
tape	O
drive	O
or	O
a	O
file	O
on	O
a	O
hard	O
drive	O
)	O
.	O
</s>
<s>
A	O
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
is	O
not	O
a	O
stable	O
sort	O
.	O
</s>
<s>
A	O
merge	B-Algorithm
sort	I-Algorithm
splits	O
the	O
records	O
of	O
a	O
dataset	O
into	O
sorted	O
runs	O
of	O
records	O
and	O
then	O
repeatedly	O
merges	O
sorted	O
runs	O
into	O
larger	O
sorted	O
runs	O
until	O
only	O
one	O
run	O
,	O
the	O
sorted	O
dataset	O
,	O
remains	O
.	O
</s>
<s>
An	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
using	O
four	O
working	O
files	O
organizes	O
them	O
as	O
a	O
pair	O
of	O
input	O
files	O
and	O
a	O
pair	O
of	O
output	O
files	O
.	O
</s>
<s>
If	O
there	O
are	O
only	O
three	O
working	O
files	O
,	O
then	O
an	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
merges	O
sorted	O
runs	O
from	O
two	O
working	O
files	O
onto	O
a	O
single	O
working	O
file	O
,	O
then	O
distributes	O
the	O
runs	O
evenly	O
between	O
the	O
two	O
output	O
files	O
.	O
</s>
<s>
In	O
general	O
,	O
for	O
an	O
even	O
number	O
N	O
of	O
working	O
files	O
,	O
each	O
iteration	O
of	O
an	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
reduces	O
run	O
count	O
by	O
a	O
factor	O
of	O
N/2	O
,	O
while	O
for	O
an	O
odd	O
number	O
N	O
of	O
working	O
files	O
,	O
each	O
iteration	O
reduces	O
the	O
run	O
count	O
by	O
an	O
average	O
factor	O
of	O
=	O
/2	O
.	O
</s>
<s>
For	O
N	O
8	O
working	O
files	O
,	O
a	O
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
achieves	O
a	O
higher	O
effective	O
run	O
count	O
reduction	O
factor	O
by	O
unevenly	O
distributing	O
sorted	O
runs	O
between	O
N−1	O
working	O
files	O
(	O
explained	O
in	O
next	O
section	O
)	O
.	O
</s>
<s>
When	O
the	O
end	O
of	O
one	O
of	O
the	O
N−1	O
working	O
files	O
is	O
reached	O
,	O
then	O
it	O
becomes	O
the	O
new	O
output	O
file	O
and	O
what	O
was	O
the	O
output	O
file	O
becomes	O
one	O
of	O
the	O
N−1	O
working	O
input	O
files	O
,	O
starting	O
a	O
new	O
iteration	O
of	O
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
For	O
each	O
polyphase	O
iteration	O
,	O
the	O
total	O
number	O
of	O
runs	O
follows	O
a	O
pattern	O
similar	O
to	O
a	O
reversed	O
Fibonacci	B-Algorithm
numbers	I-Algorithm
of	O
higher	O
order	O
sequence	O
.	O
</s>
<s>
For	O
a	O
dataset	O
consisting	O
of	O
57	O
runs	O
of	O
1	O
record	O
each	O
,	O
then	O
after	O
the	O
initial	O
distribution	O
,	O
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
moves	O
232	O
records	O
during	O
the	O
6	O
iterations	O
it	O
takes	O
to	O
sort	O
the	O
dataset	O
,	O
for	O
an	O
overall	O
reduction	O
factor	O
of	O
2.70	O
(	O
this	O
is	O
explained	O
in	O
more	O
detail	O
later	O
)	O
.	O
</s>
<s>
Looking	O
at	O
the	O
perfect	O
3	O
file	O
case	O
,	O
the	O
number	O
of	O
runs	O
for	O
merged	O
working	O
backwards	O
:	O
1	O
,	O
1	O
,	O
2	O
,	O
3	O
,	O
5	O
,	O
...	O
reveals	O
a	O
Fibonacci	B-Algorithm
sequence	I-Algorithm
.	O
</s>
<s>
Consequently	O
,	O
the	O
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
needs	O
to	O
be	O
clever	O
about	O
the	O
initial	O
distribution	O
of	O
the	O
input	O
data	O
's	O
runs	O
to	O
the	O
initial	O
output	O
files	O
.	O
</s>
<s>
Define	O
Fi	O
=	O
Fi−1	O
+	O
Fi−2	O
as	O
the	O
ith	O
Fibonacci	B-Algorithm
number	I-Algorithm
.	O
</s>
<s>
After	O
the	O
initial	O
distribution	O
,	O
an	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
using	O
4	O
files	O
will	O
sort	O
16	O
single	O
record	O
runs	O
in	O
4	O
iterations	O
of	O
the	O
entire	O
dataset	O
,	O
moving	O
a	O
total	O
of	O
64	O
records	O
in	O
order	O
to	O
sort	O
the	O
dataset	O
after	O
the	O
initial	O
distribution	O
.	O
</s>
<s>
A	O
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
using	O
4	O
files	O
will	O
sort	O
17	O
single	O
record	O
runs	O
in	O
4	O
iterations	O
,	O
but	O
since	O
each	O
iteration	O
but	O
the	O
last	O
iteration	O
only	O
moves	O
a	O
fraction	O
of	O
the	O
dataset	O
,	O
it	O
only	O
moves	O
a	O
total	O
of	O
48	O
records	O
in	O
order	O
to	O
sort	O
the	O
dataset	O
after	O
the	O
initial	O
distribution	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
factor	O
is	O
2.0	O
,	O
while	O
polyphase	O
overall	O
factor	O
is	O
≈	O
2.73	O
.	O
</s>
<s>
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
→	O
,	O
</s>
<s>
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
→	O
.	O
</s>
<s>
Here	O
is	O
a	O
table	O
of	O
effective	O
reduction	O
factors	O
for	O
polyphase	O
and	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
listed	O
by	O
number	O
of	O
files	O
,	O
based	O
on	O
actual	O
sorts	O
of	O
a	O
few	O
million	O
records	O
.	O
</s>
<s>
In	O
general	O
,	O
polyphase	B-Algorithm
merge	I-Algorithm
sort	I-Algorithm
is	O
better	O
than	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
when	O
there	O
are	O
fewer	O
than	O
8	O
files	O
,	O
while	O
ordinary	O
merge	B-Algorithm
sort	I-Algorithm
starts	O
to	O
become	O
better	O
at	O
around	O
8	O
or	O
more	O
files	O
.	O
</s>
