<s>
Comb	B-Algorithm
sort	I-Algorithm
is	O
a	O
relatively	O
simple	O
sorting	B-Algorithm
algorithm	I-Algorithm
originally	O
designed	O
by	O
Włodzimierz	O
Dobosiewicz	O
and	O
Artur	O
Borowy	O
in	O
1980	O
,	O
later	O
rediscovered	O
(	O
and	O
given	O
the	O
name	O
"	O
Combsort	B-Algorithm
"	O
)	O
by	O
Stephen	O
Lacey	O
and	O
Richard	O
Box	O
in	O
1991	O
.	O
</s>
<s>
Comb	B-Algorithm
sort	I-Algorithm
improves	O
on	O
bubble	B-Algorithm
sort	I-Algorithm
in	O
the	O
same	O
way	O
that	O
Shellsort	B-Algorithm
improves	O
on	O
insertion	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
nist.govs	O
"	O
diminishing	O
increment	O
sort	O
"	O
definition	O
mentions	O
the	O
term	O
'	O
comb	B-Algorithm
sort	I-Algorithm
 '	O
as	O
visualizing	O
iterative	O
passes	O
of	O
the	O
data	O
,	O
"	O
where	O
the	O
teeth	O
of	O
a	O
comb	O
touch	O
;	O
"	O
the	O
former	O
term	O
is	O
linked	O
to	O
Don	O
Knuth	O
.	O
</s>
<s>
The	O
basic	O
idea	O
is	O
to	O
eliminate	O
turtles	O
,	O
or	O
small	O
values	O
near	O
the	O
end	O
of	O
the	O
list	O
,	O
since	O
in	O
a	O
bubble	B-Algorithm
sort	I-Algorithm
these	O
slow	O
the	O
sorting	B-Algorithm
down	O
tremendously	O
.	O
</s>
<s>
Rabbits	O
,	O
large	O
values	O
around	O
the	O
beginning	O
of	O
the	O
list	O
,	O
do	O
not	O
pose	O
a	O
problem	O
in	O
bubble	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
In	O
bubble	B-Algorithm
sort	I-Algorithm
,	O
when	O
any	O
two	O
elements	O
are	O
compared	O
,	O
they	O
always	O
have	O
a	O
gap	O
(	O
distance	O
from	O
each	O
other	O
)	O
of	O
1	O
.	O
</s>
<s>
The	O
basic	O
idea	O
of	O
comb	B-Algorithm
sort	I-Algorithm
is	O
that	O
the	O
gap	O
can	O
be	O
much	O
more	O
than	O
1	O
.	O
</s>
<s>
The	O
inner	O
loop	O
of	O
bubble	B-Algorithm
sort	I-Algorithm
,	O
which	O
does	O
the	O
actual	O
swap	O
,	O
is	O
modified	O
such	O
that	O
the	O
gap	O
between	O
swapped	O
elements	O
goes	O
down	O
(	O
for	O
each	O
iteration	O
of	O
outer	O
loop	O
)	O
in	O
steps	O
of	O
a	O
"	O
shrink	O
factor	O
"	O
k	O
:	O
.	O
</s>
<s>
The	O
gap	O
starts	O
out	O
as	O
the	O
length	O
of	O
the	O
list	O
n	O
being	O
sorted	O
divided	O
by	O
the	O
shrink	O
factor	O
k	O
(	O
generally	O
1.3	O
;	O
see	O
below	O
)	O
and	O
one	O
pass	O
of	O
the	O
aforementioned	O
modified	O
bubble	B-Algorithm
sort	I-Algorithm
is	O
applied	O
with	O
that	O
gap	O
.	O
</s>
<s>
At	O
this	O
point	O
,	O
comb	B-Algorithm
sort	I-Algorithm
continues	O
using	O
a	O
gap	O
of	O
1	O
until	O
the	O
list	O
is	O
fully	O
sorted	O
.	O
</s>
<s>
The	O
final	O
stage	O
of	O
the	O
sort	O
is	O
thus	O
equivalent	O
to	O
a	O
bubble	B-Algorithm
sort	I-Algorithm
,	O
but	O
by	O
this	O
time	O
most	O
turtles	O
have	O
been	O
dealt	O
with	O
,	O
so	O
a	O
bubble	B-Algorithm
sort	I-Algorithm
will	O
be	O
efficient	O
.	O
</s>
<s>
The	O
shrink	O
factor	O
has	O
a	O
great	O
effect	O
on	O
the	O
efficiency	O
of	O
comb	B-Algorithm
sort	I-Algorithm
.	O
</s>
<s>
The	O
pattern	O
of	O
repeated	O
sorting	B-Algorithm
passes	O
with	O
decreasing	O
gaps	O
is	O
similar	O
to	O
Shellsort	B-Algorithm
,	O
but	O
in	O
Shellsort	B-Algorithm
the	O
array	B-Data_Structure
is	O
sorted	O
completely	O
each	O
pass	O
before	O
going	O
on	O
to	O
the	O
next-smallest	O
gap	O
.	O
</s>
<s>
Comb	B-Algorithm
sort	I-Algorithm
's	O
passes	O
do	O
not	O
completely	O
sort	O
the	O
elements	O
.	O
</s>
<s>
This	O
is	O
the	O
reason	O
that	O
Shellsort	B-Algorithm
gap	O
sequences	O
have	O
a	O
larger	O
optimal	O
shrink	O
factor	O
of	O
about	O
2.2	O
.	O
</s>
<s>
Plus	O
,	O
two	O
quick	O
Python	B-Language
implementations	O
:	O
one	O
works	O
on	O
the	O
list	O
(	O
or	O
array	B-Data_Structure
,	O
or	O
other	O
mutable	O
type	O
where	O
the	O
operations	O
used	O
on	O
it	O
make	O
sense	O
to	O
the	O
language	O
)	O
in-place	O
,	O
the	O
other	O
makes	O
a	O
list	O
with	O
the	O
same	O
values	O
as	O
the	O
given	O
data	O
and	O
returns	O
that	O
after	O
sorting	B-Algorithm
it	O
(	O
similar	O
to	O
the	O
builtin	O
sorted	O
function	O
)	O
.	O
</s>
