<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
sorting	B-Algorithm
is	O
the	O
problem	O
of	O
sorting	B-Algorithm
pairs	O
of	O
numbers	O
by	O
their	O
sums	O
.	O
</s>
<s>
As	O
with	O
comparison	B-Algorithm
sorting	I-Algorithm
and	O
integer	B-Algorithm
sorting	I-Algorithm
more	O
generally	O
,	O
algorithms	O
for	O
this	O
problem	O
can	O
be	O
based	O
only	O
on	O
comparisons	O
of	O
these	O
sums	O
,	O
or	O
on	O
other	O
operations	O
that	O
work	O
only	O
when	O
the	O
inputs	O
are	O
small	O
integers	O
.	O
</s>
<s>
It	O
is	O
unknown	O
whether	O
this	O
problem	O
has	O
a	O
comparison-based	O
solution	O
whose	O
running	O
time	O
is	O
asymptotically	O
faster	O
than	O
sorting	B-Algorithm
an	O
unstructured	O
list	O
of	O
equally	O
many	O
items	O
.	O
</s>
<s>
Therefore	O
,	O
research	O
on	O
the	O
problem	O
has	O
focused	O
on	O
two	O
approaches	O
to	O
settle	O
the	O
question	O
of	O
whether	O
such	O
an	O
improvement	O
is	O
possible	O
:	O
the	O
development	O
of	O
algorithms	O
that	O
improve	O
on	O
unstructured	O
sorting	B-Algorithm
in	O
their	O
number	O
of	O
comparisons	O
rather	O
than	O
in	O
their	O
total	O
running	O
time	O
,	O
and	O
lower	O
bounds	O
for	O
the	O
number	O
of	O
comparisons	O
based	O
on	O
counting	O
cells	O
in	O
subdivisions	O
of	O
high-dimensional	O
spaces	O
.	O
</s>
<s>
The	O
input	O
to	O
the	O
sorting	B-Algorithm
problem	I-Algorithm
consists	O
of	O
two	O
finite	O
collections	B-Application
of	O
numbers	O
and	O
,	O
of	O
the	O
same	O
length	O
.	O
</s>
<s>
As	O
a	O
small	O
example	O
,	O
for	O
the	O
inputs	O
and	O
,	O
the	O
output	O
should	O
be	O
the	O
list	O
of	O
pairsof	O
one	O
element	O
from	O
and	O
one	O
element	O
from	O
,	O
listed	O
in	O
sorted	O
order	O
by	O
their	O
sums	O
of	O
pairsOne	O
way	O
to	O
solve	O
the	O
problem	O
would	O
be	O
to	O
construct	O
the	O
pairs	O
to	O
be	O
sorted	O
(	O
the	O
Cartesian	O
product	O
of	O
the	O
two	O
collections	B-Application
)	O
and	O
use	O
these	O
pairs	O
as	O
input	O
to	O
a	O
standard	O
comparison	B-Algorithm
sorting	I-Algorithm
algorithm	O
such	O
as	O
merge	B-Algorithm
sort	I-Algorithm
or	O
heapsort	B-Application
.	O
</s>
<s>
In	O
terms	O
of	O
its	O
big	O
O	O
notation	O
,	O
this	O
method	O
is	O
the	O
fastest	O
known	O
algorithm	O
for	O
sorting	B-Algorithm
.	O
</s>
<s>
For	O
this	O
variant	O
,	O
the	O
size	O
of	O
the	O
sumset	O
may	O
be	O
significantly	O
smaller	O
than	O
,	O
and	O
output-sensitive	B-Language
algorithms	I-Language
for	O
constructing	O
it	O
have	O
been	O
investigated	O
.	O
</s>
<s>
Skiena	O
's	O
solution	O
consists	O
of	O
sorting	B-Algorithm
pairs	O
of	O
hops	O
by	O
their	O
total	O
cost	O
as	O
an	O
instance	O
of	O
the	O
sorting	B-Algorithm
problem	I-Algorithm
,	O
and	O
then	O
testing	O
the	O
resulting	O
pairs	O
in	O
this	O
sorted	O
order	O
until	O
finding	O
one	O
that	O
is	O
allowed	O
.	O
</s>
<s>
To	O
generate	O
the	O
sorted	O
pairs	O
in	O
this	O
order	O
,	O
Skiena	O
uses	O
a	O
priority	B-Application
queue	I-Application
of	O
pairs	O
,	O
initially	O
containing	O
only	O
a	O
single	O
pair	O
,	O
the	O
one	O
consisting	O
of	O
the	O
two	O
cheapest	O
hops	O
.	O
</s>
<s>
Then	O
,	O
when	O
a	O
pair	O
is	O
removed	O
from	O
the	O
queue	O
and	O
found	O
to	O
be	O
disallowed	O
,	O
two	O
more	O
pairs	O
are	O
added	O
,	O
with	O
one	O
of	O
these	O
two	O
pairs	O
combining	O
with	O
the	O
next	O
hop	O
after	O
in	O
a	O
sorted	B-Algorithm
list	I-Algorithm
of	O
the	O
hops	O
to	O
the	O
destination	O
,	O
and	O
the	O
other	O
pair	O
combining	O
with	O
the	O
next	O
hop	O
after	O
in	O
a	O
sorted	B-Algorithm
list	I-Algorithm
of	O
hops	O
from	O
the	O
start	O
.	O
</s>
<s>
sorting	B-Algorithm
is	O
the	O
most	O
expensive	O
subroutine	O
in	O
an	O
algorithm	O
for	O
a	O
problem	O
in	O
VLSI	O
design	O
,	O
in	O
which	O
one	O
must	O
place	O
two	O
subunits	O
of	O
a	O
VLSI	O
circuit	O
side-by-side	O
along	O
a	O
communications	O
channel	O
in	O
order	O
to	O
minimize	O
the	O
width	O
of	O
the	O
channel	O
needed	O
to	O
route	O
pairs	O
of	O
wires	O
from	O
one	O
subunit	O
to	O
the	O
other	O
.	O
</s>
<s>
As	O
one	O
subunit	O
is	O
continuously	O
shifted	O
relative	O
to	O
the	O
other	O
,	O
the	O
channel	O
width	O
only	O
changes	O
at	O
discrete	O
positions	O
where	O
the	O
ends	O
of	O
two	O
wires	O
line	O
up	O
with	O
each	O
other	O
,	O
and	O
finding	O
the	O
sorted	O
ordering	O
of	O
these	O
positions	O
in	O
order	O
to	O
compute	O
the	O
sequence	O
of	O
changes	O
to	O
the	O
width	O
can	O
be	O
performed	O
by	O
sorting	B-Algorithm
.	O
</s>
<s>
If	O
this	O
sorting	B-Algorithm
problem	I-Algorithm
could	O
be	O
sped	O
up	O
,	O
it	O
would	O
also	O
speed	O
up	O
this	O
VLSI	O
design	O
task	O
.	O
</s>
<s>
The	O
product	O
of	O
two	O
polynomials	O
can	O
be	O
expressed	O
as	O
a	O
sum	O
of	O
products	O
of	O
pairs	O
of	O
terms	O
,	O
one	O
from	O
each	O
polynomial	O
,	O
and	O
placing	O
these	O
term-by-term	O
products	O
into	O
degree	O
order	O
amounts	O
to	O
sorting	B-Algorithm
them	O
by	O
the	O
sum	O
of	O
degrees	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
instance	O
of	O
sorting	B-Algorithm
with	O
given	O
as	O
an	O
example	O
above	O
corresponds	O
to	O
the	O
multiplication	O
of	O
two	O
three-term	O
polynomials	O
to	O
produce	O
a	O
nine-term	O
polynomial	O
:	O
</s>
<s>
The	O
degrees	O
are	O
always	O
integers	O
,	O
so	O
integer-based	O
algorithms	O
for	O
sorting	B-Algorithm
may	O
be	O
applied	O
.	O
</s>
<s>
A	O
well-known	O
lower	O
bound	O
for	O
unstructured	O
sorting	B-Algorithm
,	O
in	O
the	O
decision	B-Application
tree	I-Application
model	I-Application
,	O
is	O
based	O
on	O
the	O
factorial	O
number	O
of	O
sorted	O
orders	O
that	O
an	O
unstructured	O
list	O
may	O
have	O
.	O
</s>
<s>
Because	O
each	O
comparison	O
can	O
at	O
best	O
reduce	O
the	O
number	O
of	O
possible	O
orderings	O
by	O
a	O
factor	O
of	O
two	O
,	O
sorting	B-Algorithm
requires	O
a	O
number	O
of	O
comparisons	O
at	O
least	O
equal	O
to	O
the	O
binary	O
logarithm	O
of	O
the	O
factorial	O
,	O
which	O
is	O
.	O
</s>
<s>
Early	O
work	O
on	O
sorting	B-Algorithm
followed	O
a	O
similar	O
approach	O
by	O
asking	O
how	O
many	O
different	O
sorted	O
orderings	O
are	O
possible	O
for	O
this	O
problem	O
,	O
and	O
proving	O
that	O
this	O
number	O
is	O
at	O
most	O
.	O
</s>
<s>
However	O
,	O
because	O
its	O
binary	O
logarithm	O
is	O
at	O
most	O
,	O
much	O
smaller	O
than	O
the	O
known	O
time	O
bounds	O
for	O
sorting	B-Algorithm
,	O
this	O
method	O
can	O
only	O
lead	O
to	O
weak	O
lower	O
bounds	O
on	O
the	O
number	O
of	O
comparisons	O
.	O
</s>
<s>
The	O
proof	O
of	O
this	O
bound	O
relates	O
sorting	B-Algorithm
to	O
the	O
complexity	O
of	O
an	O
arrangement	O
of	O
hyperplanes	O
in	O
high-dimensional	O
geometry	O
.	O
</s>
<s>
The	O
two	O
input	O
collections	B-Application
for	O
the	O
sorting	B-Algorithm
problem	I-Algorithm
comprise	O
numbers	O
,	O
which	O
can	O
alternatively	O
be	O
interpreted	O
as	O
the	O
Cartesian	O
coordinates	O
of	O
a	O
point	O
in	O
the	O
-dimensional	O
space	O
.	O
</s>
<s>
A	O
similar	O
style	O
of	O
analysis	O
has	O
been	O
more	O
successful	O
in	O
ruling	O
out	O
fast	O
solutions	O
to	O
certain	O
generalizations	O
of	O
sorting	B-Algorithm
,	O
by	O
showing	O
that	O
they	O
have	O
too	O
many	O
orderings	O
to	O
sort	O
quickly	O
.	O
</s>
<s>
In	O
particular	O
,	O
suggest	O
separately	O
sorting	B-Algorithm
and	O
,	O
and	O
then	O
constructing	O
a	O
two-dimensional	O
matrix	O
of	O
the	O
values	O
of	O
that	O
is	O
sorted	O
both	O
by	O
rows	O
and	O
by	O
columns	O
before	O
using	O
this	O
partially-sorted	O
data	O
to	O
complete	O
the	O
sort	O
of	O
.	O
</s>
<s>
This	O
idea	O
of	O
using	O
a	O
row-sorted	O
and	O
column-sorted	O
matrix	O
forms	O
the	O
basis	O
for	O
the	O
method	O
used	O
by	O
Skiena	O
in	O
the	O
transportation	O
application	O
,	O
and	O
it	O
can	O
reduce	O
the	O
number	O
of	O
comparisons	O
by	O
a	O
constant	O
factor	O
relative	O
to	O
naive	O
comparison	B-Algorithm
sorting	I-Algorithm
.	O
</s>
<s>
However	O
,	O
for	O
matrices	O
whose	O
rows	O
and	O
columns	O
are	O
sorted	O
in	O
this	O
way	O
,	O
the	O
number	O
of	O
possible	O
sorted	O
orderings	O
of	O
the	O
whole	O
matrix	O
is	O
much	O
larger	O
than	O
,	O
so	O
large	O
that	O
any	O
comparison	B-Algorithm
sorting	I-Algorithm
algorithm	O
that	O
can	O
work	O
for	O
arbitrary	O
matrices	O
that	O
are	O
sorted	O
by	O
rows	O
and	O
columns	O
still	O
requires	O
comparisons	O
.	O
</s>
<s>
For	O
the	O
classical	O
comparison	B-Algorithm
sorting	I-Algorithm
problem	O
,	O
the	O
time	O
to	O
sort	O
and	O
the	O
number	O
of	O
comparisons	O
needed	O
to	O
sort	O
are	O
within	O
constant	O
factors	O
of	O
each	O
other	O
.	O
</s>
<s>
But	O
for	O
sorting	B-Algorithm
,	O
the	O
number	O
of	O
comparisons	O
is	O
smaller	O
than	O
the	O
best	O
time	O
bound	O
known	O
:	O
Michael	O
Fredman	O
showed	O
in	O
1976	O
that	O
sorting	B-Algorithm
can	O
be	O
done	O
using	O
only	O
comparisons	O
.	O
</s>
<s>
For	O
the	O
sorting	B-Algorithm
problem	I-Algorithm
,	O
,	O
and	O
,	O
so	O
and	O
Fredman	O
's	O
bound	O
implies	O
that	O
only	O
comparisons	O
are	O
needed	O
.	O
</s>
<s>
Merge	B-Algorithm
the	O
two	O
sets	O
and	O
into	O
a	O
single	O
sorted	O
order	O
,	O
using	O
a	O
number	O
of	O
comparisons	O
linear	O
in	O
their	O
total	O
size	O
.	O
</s>
<s>
Infer	O
the	O
ordering	O
on	O
using	O
only	O
the	O
comparisons	O
from	O
a	O
single	O
merge	B-Algorithm
step	O
as	O
above	O
.	O
</s>
<s>
Merge	B-Algorithm
the	O
sorted	O
results	O
,	O
,	O
and	O
together	O
.	O
</s>
<s>
where	O
the	O
term	O
of	O
the	O
recurrence	O
counts	O
the	O
number	O
of	O
comparisons	O
in	O
the	O
recursive	O
calls	O
to	O
the	O
algorithm	O
to	O
sort	O
and	O
,	O
and	O
the	O
term	O
counts	O
the	O
number	O
of	O
comparisons	O
used	O
to	O
merge	B-Algorithm
the	O
results	O
.	O
</s>
<s>
The	O
master	B-Algorithm
theorem	I-Algorithm
for	O
recurrence	O
relations	O
of	O
this	O
form	O
shows	O
that	O
The	O
total	O
time	O
complexity	O
is	O
slower	O
,	O
,	O
because	O
of	O
the	O
steps	O
of	O
the	O
algorithm	O
that	O
use	O
already-made	O
comparisons	O
to	O
infer	O
orderings	O
of	O
other	O
sets	O
.	O
</s>
<s>
Just	O
as	O
integer	B-Algorithm
sorting	I-Algorithm
can	O
be	O
faster	O
than	O
comparison	B-Algorithm
sorting	I-Algorithm
for	O
small-enough	O
integers	O
,	O
the	O
same	O
is	O
true	O
for	O
sorting	B-Algorithm
.	O
</s>
<s>
Several	O
other	O
problems	O
in	O
computational	O
geometry	O
have	O
equivalent	O
or	O
harder	O
complexity	O
to	O
sorting	B-Algorithm
,	O
including	O
constructing	O
Minkowski	B-Algorithm
sums	I-Algorithm
of	O
staircase	O
polygons	O
,	O
finding	O
the	O
crossing	O
points	O
of	O
an	O
arrangement	O
of	O
lines	O
in	O
sorted	O
order	O
by	O
their	O
-coordinates	O
,	O
listing	O
pairs	O
of	O
points	O
in	O
sorted	O
order	O
by	O
their	O
distances	O
,	O
and	O
testing	O
whether	O
one	O
rectilinear	O
polygon	O
can	O
be	O
translated	O
to	O
fit	O
within	O
another	O
.	O
</s>
<s>
The	O
problem	O
of	O
testing	O
whether	O
two	O
of	O
the	O
pairs	O
in	O
the	O
sorting	B-Algorithm
problem	I-Algorithm
have	O
equal	O
sums	O
can	O
be	O
solved	O
by	O
sorting	B-Algorithm
the	O
pairs	O
and	O
then	O
testing	O
consecutive	O
pairs	O
for	O
equality	O
.	O
</s>
