<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
comparator	O
networks	O
are	O
abstract	O
devices	O
built	O
up	O
of	O
a	O
fixed	O
number	O
of	O
"	O
wires	O
"	O
,	O
carrying	O
values	O
,	O
and	O
comparator	O
modules	O
that	O
connect	O
pairs	O
of	O
wires	O
,	O
swapping	O
the	O
values	O
on	O
the	O
wires	O
if	O
they	O
are	O
not	O
in	O
a	O
desired	O
order	O
.	O
</s>
<s>
Such	O
networks	O
are	O
typically	O
designed	O
to	O
perform	O
sorting	B-Algorithm
on	O
fixed	O
numbers	O
of	O
values	O
,	O
in	O
which	O
case	O
they	O
are	O
called	O
sorting	B-Algorithm
networks	I-Algorithm
.	O
</s>
<s>
Sorting	B-Algorithm
networks	I-Algorithm
differ	O
from	O
general	O
comparison	B-Algorithm
sorts	I-Algorithm
in	O
that	O
they	O
are	O
not	O
capable	O
of	O
handling	O
arbitrarily	O
large	O
inputs	O
,	O
and	O
in	O
that	O
their	O
sequence	O
of	O
comparisons	O
is	O
set	O
in	O
advance	O
,	O
regardless	O
of	O
the	O
outcome	O
of	O
previous	O
comparisons	O
.	O
</s>
<s>
In	O
order	O
to	O
sort	O
larger	O
amounts	O
of	O
inputs	O
,	O
new	O
sorting	B-Algorithm
networks	I-Algorithm
must	O
be	O
constructed	O
.	O
</s>
<s>
This	O
independence	O
of	O
comparison	O
sequences	O
is	O
useful	O
for	O
parallel	O
execution	O
and	O
for	O
implementation	O
in	O
hardware	B-Architecture
.	O
</s>
<s>
Despite	O
the	O
simplicity	O
of	O
sorting	B-Algorithm
nets	I-Algorithm
,	O
their	O
theory	O
is	O
surprisingly	O
deep	O
and	O
complex	O
.	O
</s>
<s>
Sorting	B-Algorithm
networks	I-Algorithm
were	O
first	O
studied	O
circa	O
1954	O
by	O
Armstrong	O
,	O
Nelson	O
and	O
O'Connor	O
,	O
who	O
subsequently	O
patented	O
the	O
idea	O
.	O
</s>
<s>
Sorting	B-Algorithm
networks	I-Algorithm
can	O
be	O
implemented	O
either	O
in	O
hardware	B-Architecture
or	O
in	O
software	O
.	O
</s>
<s>
Batcher	O
,	O
in	O
1968	O
,	O
suggested	O
using	O
them	O
to	O
construct	O
switching	O
networks	O
for	O
computer	B-Architecture
hardware	I-Architecture
,	O
replacing	O
both	O
buses	B-General_Concept
and	O
the	O
faster	O
,	O
but	O
more	O
expensive	O
,	O
crossbar	O
switches	O
.	O
</s>
<s>
Since	O
the	O
2000s	O
,	O
sorting	B-Algorithm
nets	I-Algorithm
(	O
especially	O
bitonic	B-Algorithm
mergesort	I-Algorithm
)	O
are	O
used	O
by	O
the	O
GPGPU	B-Architecture
community	O
for	O
constructing	O
sorting	B-Algorithm
algorithms	I-Algorithm
to	O
run	O
on	O
graphics	B-Architecture
processing	I-Architecture
units	I-Architecture
.	O
</s>
<s>
A	O
sorting	B-Algorithm
network	I-Algorithm
consists	O
of	O
two	O
types	O
of	O
items	O
:	O
comparators	O
and	O
wires	O
.	O
</s>
<s>
A	O
network	O
of	O
wires	O
and	O
comparators	O
that	O
will	O
correctly	O
sort	O
all	O
possible	O
inputs	O
into	O
ascending	O
order	O
is	O
called	O
a	O
sorting	B-Algorithm
network	I-Algorithm
or	O
Kruskal	O
hub	O
.	O
</s>
<s>
The	O
full	O
operation	O
of	O
a	O
simple	O
sorting	B-Algorithm
network	I-Algorithm
is	O
shown	O
below	O
.	O
</s>
<s>
It	O
is	O
evident	O
why	O
this	O
sorting	B-Algorithm
network	I-Algorithm
will	O
correctly	O
sort	O
the	O
inputs	O
;	O
note	O
that	O
the	O
first	O
four	O
comparators	O
will	O
"	O
sink	O
"	O
the	O
largest	O
value	O
to	O
the	O
bottom	O
and	O
"	O
float	O
"	O
the	O
smallest	O
value	O
to	O
the	O
top	O
.	O
</s>
<s>
The	O
efficiency	O
of	O
a	O
sorting	B-Algorithm
network	I-Algorithm
can	O
be	O
measured	O
by	O
its	O
total	O
size	O
,	O
meaning	O
the	O
number	O
of	O
comparators	O
in	O
the	O
network	O
,	O
or	O
by	O
its	O
depth	O
,	O
defined	O
(	O
informally	O
)	O
as	O
the	O
largest	O
number	O
of	O
comparators	O
that	O
any	O
input	O
value	O
can	O
encounter	O
on	O
its	O
way	O
through	O
the	O
network	O
.	O
</s>
<s>
Noting	O
that	O
sorting	B-Algorithm
networks	I-Algorithm
can	O
perform	O
certain	O
comparisons	O
in	B-Operating_System
parallel	I-Operating_System
(	O
represented	O
in	O
the	O
graphical	O
notation	O
by	O
comparators	O
that	O
lie	O
on	O
the	O
same	O
vertical	O
line	O
)	O
,	O
and	O
assuming	O
all	O
comparisons	O
to	O
take	O
unit	O
time	O
,	O
it	O
can	O
be	O
seen	O
that	O
the	O
depth	O
of	O
the	O
network	O
is	O
equal	O
to	O
the	O
number	O
of	O
time	O
steps	O
required	O
to	O
execute	O
it	O
.	O
</s>
<s>
Assuming	O
we	O
have	O
a	O
sorting	B-Algorithm
network	I-Algorithm
of	O
size	O
n	O
,	O
we	O
can	O
construct	O
a	O
network	O
of	O
size	O
by	O
"	O
inserting	O
"	O
an	O
additional	O
number	O
into	O
the	O
already	O
sorted	O
subnet	O
(	O
using	O
the	O
principle	O
behind	O
insertion	B-Algorithm
sort	I-Algorithm
)	O
.	O
</s>
<s>
We	O
can	O
also	O
accomplish	O
the	O
same	O
thing	O
by	O
first	O
"	O
selecting	O
"	O
the	O
lowest	O
value	O
from	O
the	O
inputs	O
and	O
then	O
sort	O
the	O
remaining	O
values	O
recursively	O
(	O
using	O
the	O
principle	O
behind	O
bubble	B-Algorithm
sort	I-Algorithm
)	O
.	O
</s>
<s>
200px|thumb|A	O
sorting	B-Algorithm
network	I-Algorithm
constructed	O
recursively	O
that	O
first	O
sorts	O
the	O
first	O
n	O
wires	O
,	O
and	O
then	O
inserts	O
the	O
remaining	O
value	O
.	O
</s>
<s>
Based	O
on	O
insertion	O
sortThe	O
structure	O
of	O
these	O
two	O
sorting	B-Algorithm
networks	I-Algorithm
are	O
very	O
similar	O
.	O
</s>
<s>
This	O
is	O
better	O
than	O
the	O
time	O
needed	O
by	O
random-access	B-Application
machines	I-Application
,	O
but	O
it	O
turns	O
out	O
that	O
there	O
are	O
much	O
more	O
efficient	O
sorting	B-Algorithm
networks	I-Algorithm
with	O
a	O
depth	O
of	O
just	O
,	O
as	O
described	O
below	O
.	O
</s>
<s>
While	O
it	O
is	O
easy	O
to	O
prove	O
the	O
validity	O
of	O
some	O
sorting	B-Algorithm
networks	I-Algorithm
(	O
like	O
the	O
insertion/bubble	O
sorter	O
)	O
,	O
it	O
is	O
not	O
always	O
so	O
easy	O
.	O
</s>
<s>
The	O
zero-one	O
principle	O
states	O
that	O
,	O
if	O
a	O
sorting	B-Algorithm
network	I-Algorithm
can	O
correctly	O
sort	O
all	O
sequences	O
of	O
zeros	O
and	O
ones	O
,	O
then	O
it	O
is	O
also	O
valid	O
for	O
arbitrary	O
ordered	O
inputs	O
.	O
</s>
<s>
This	O
not	O
only	O
drastically	O
cuts	O
down	O
on	O
the	O
number	O
of	O
tests	O
needed	O
to	O
ascertain	O
the	O
validity	O
of	O
a	O
network	O
,	O
it	O
is	O
of	O
great	O
use	O
in	O
creating	O
many	O
constructions	O
of	O
sorting	B-Algorithm
networks	I-Algorithm
as	O
well	O
.	O
</s>
<s>
By	B-Algorithm
induction	I-Algorithm
on	O
the	O
depth	O
of	O
the	O
network	O
,	O
this	O
result	O
can	O
be	O
extended	O
to	O
a	O
lemma	O
stating	O
that	O
if	O
the	O
network	O
transforms	O
the	O
sequence	O
into	O
,	O
it	O
will	O
transform	O
into	O
.	O
</s>
<s>
Various	O
algorithms	O
exist	O
to	O
construct	O
sorting	B-Algorithm
networks	I-Algorithm
of	O
depth	O
(	O
hence	O
size	O
)	O
such	O
as	O
Batcher	B-Algorithm
odd	I-Algorithm
–	I-Algorithm
even	I-Algorithm
mergesort	I-Algorithm
,	O
bitonic	B-Algorithm
sort	I-Algorithm
,	O
Shell	B-Algorithm
sort	I-Algorithm
,	O
and	O
the	O
Pairwise	B-Algorithm
sorting	I-Algorithm
network	I-Algorithm
.	O
</s>
<s>
It	O
is	O
also	O
possible	O
to	O
construct	O
networks	O
of	O
depth	O
(	O
hence	O
size	O
)	O
using	O
a	O
construction	O
called	O
the	O
AKS	B-Algorithm
network	I-Algorithm
,	O
after	O
its	O
discoverers	O
Ajtai	O
,	O
Komlós	O
,	O
and	O
Szemerédi	O
.	O
</s>
<s>
While	O
an	O
important	O
theoretical	O
discovery	O
,	O
the	O
AKS	B-Algorithm
network	I-Algorithm
has	O
very	O
limited	O
practical	O
application	O
because	O
of	O
the	O
large	O
linear	O
constant	O
hidden	O
by	O
the	O
Big-O	O
notation	O
.	O
</s>
<s>
A	O
simplified	O
version	O
of	O
the	O
AKS	B-Algorithm
network	I-Algorithm
was	O
described	O
by	O
Paterson	O
in	O
1990	O
,	O
who	O
noted	O
that	O
"	O
the	O
constants	O
obtained	O
for	O
the	O
depth	O
bound	O
still	O
prevent	O
the	O
construction	O
being	O
of	O
practical	O
value	O
"	O
.	O
</s>
<s>
A	O
more	O
recent	O
construction	O
called	O
the	O
zig-zag	O
sorting	B-Algorithm
network	I-Algorithm
of	O
size	O
was	O
discovered	O
by	O
Goodrich	O
in	O
2014	O
.	O
</s>
<s>
While	O
its	O
size	O
is	O
much	O
smaller	O
than	O
that	O
of	O
AKS	B-Algorithm
networks	I-Algorithm
,	O
its	O
depth	O
makes	O
it	O
unsuitable	O
for	O
a	O
parallel	O
implementation	O
.	O
</s>
<s>
For	O
small	O
,	O
fixed	O
numbers	O
of	O
inputs	O
,	O
optimal	O
sorting	B-Algorithm
networks	I-Algorithm
can	O
be	O
constructed	O
,	O
with	O
either	O
minimal	O
depth	O
(	O
for	O
maximally	O
parallel	O
execution	O
)	O
or	O
minimal	O
size	O
(	O
number	O
of	O
comparators	O
)	O
.	O
</s>
<s>
These	O
networks	O
can	O
be	O
used	O
to	O
increase	O
the	O
performance	O
of	O
larger	O
sorting	B-Algorithm
networks	I-Algorithm
resulting	O
from	O
the	O
recursive	B-Algorithm
constructions	O
of	O
,	O
e.g.	O
,	O
Batcher	O
,	O
by	O
halting	O
the	O
recursion	O
early	O
and	O
inserting	O
optimal	O
nets	O
as	O
base	O
cases	O
.	O
</s>
<s>
The	O
first	O
sixteen	O
depth-optimal	O
networks	O
are	O
listed	O
in	O
Knuth	O
's	O
Art	B-General_Concept
of	I-General_Concept
Computer	I-General_Concept
Programming	I-General_Concept
,	O
and	O
have	O
been	O
since	O
the	O
1973	O
edition	O
;	O
however	O
,	O
while	O
the	O
optimality	O
of	O
the	O
first	O
eight	O
was	O
established	O
by	O
Floyd	O
and	O
Knuth	O
in	O
the	O
1960s	O
,	O
this	O
property	O
was	O
n't	O
proven	O
for	O
the	O
final	O
six	O
until	O
2014	O
(	O
the	O
cases	O
nine	O
and	O
ten	O
having	O
been	O
decided	O
in	O
1991	O
)	O
.	O
</s>
<s>
size-optimal	O
)	O
sorting	B-Algorithm
networks	I-Algorithm
are	O
known	O
,	O
and	O
for	O
higher	O
values	O
,	O
lower	O
bounds	O
on	O
their	O
sizes	O
can	O
be	O
derived	O
inductively	O
using	O
a	O
lemma	O
due	O
to	O
Van	O
Voorhis	O
(	O
p.240	O
)	O
:	O
.	O
</s>
<s>
The	O
optimality	O
of	O
the	O
smallest	O
known	O
sorting	B-Algorithm
networks	I-Algorithm
for	O
and	O
was	O
resolved	O
in	O
2020	O
.	O
</s>
<s>
Some	O
work	O
in	O
designing	O
optimal	O
sorting	B-Algorithm
network	I-Algorithm
has	O
been	O
done	O
using	O
genetic	B-Algorithm
algorithms	I-Algorithm
:	O
D	O
.	O
Knuth	O
mentions	O
that	O
the	O
smallest	O
known	O
sorting	B-Algorithm
network	I-Algorithm
for	O
was	O
found	O
by	O
Hugues	O
Juillé	O
in	O
1995	O
"	O
by	O
simulating	O
an	O
evolutionary	O
process	O
of	O
genetic	O
breeding	O
"	O
(	O
p.226	O
)	O
,	O
and	O
that	O
the	O
minimum	O
depth	O
sorting	B-Algorithm
networks	I-Algorithm
for	O
and	O
were	O
found	O
by	O
Loren	O
Schwiebert	O
in	O
2001	O
"	O
using	O
genetic	O
methods	O
"	O
(	O
p.229	O
)	O
.	O
</s>
<s>
Unless	O
P	O
=	O
NP	O
,	O
the	O
problem	O
of	O
testing	O
whether	O
a	O
candidate	O
network	O
is	O
a	O
sorting	B-Algorithm
network	I-Algorithm
is	O
likely	O
to	O
remain	O
difficult	O
for	O
networks	O
of	O
large	O
sizes	O
,	O
due	O
to	O
the	O
problem	O
being	O
co-NP-complete	O
.	O
</s>
