<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
divide	O
and	O
conquer	O
is	O
an	O
algorithm	B-Algorithm
design	I-Algorithm
paradigm	I-Algorithm
.	O
</s>
<s>
A	O
divide-and-conquer	O
algorithm	B-Algorithm
recursively	O
breaks	O
down	O
a	O
problem	O
into	O
two	O
or	O
more	O
sub-problems	O
of	O
the	O
same	O
or	O
related	O
type	O
,	O
until	O
these	O
become	O
simple	O
enough	O
to	O
be	O
solved	O
directly	O
.	O
</s>
<s>
The	O
divide-and-conquer	O
technique	O
is	O
the	O
basis	O
of	O
efficient	O
algorithms	O
for	O
many	O
problems	O
,	O
such	O
as	O
sorting	B-Algorithm
(	O
e.g.	O
,	O
quicksort	B-Algorithm
,	O
merge	B-Algorithm
sort	I-Algorithm
)	O
,	O
multiplying	B-Algorithm
large	I-Algorithm
numbers	I-Algorithm
(	O
e.g.	O
,	O
the	O
Karatsuba	B-Algorithm
algorithm	I-Algorithm
)	O
,	O
finding	O
the	O
closest	B-Algorithm
pair	I-Algorithm
of	I-Algorithm
points	I-Algorithm
,	O
syntactic	B-Language
analysis	I-Language
(	O
e.g.	O
,	O
top-down	B-Application
parsers	I-Application
)	O
,	O
and	O
computing	O
the	O
discrete	B-Algorithm
Fourier	I-Algorithm
transform	I-Algorithm
(	O
FFT	O
)	O
.	O
</s>
<s>
As	O
in	O
mathematical	B-Algorithm
induction	I-Algorithm
,	O
it	O
is	O
often	O
necessary	O
to	O
generalize	O
the	O
problem	O
to	O
make	O
it	O
amenable	O
to	O
a	O
recursive	O
solution	O
.	O
</s>
<s>
The	O
correctness	O
of	O
a	O
divide-and-conquer	O
algorithm	B-Algorithm
is	O
usually	O
proved	O
by	O
mathematical	B-Algorithm
induction	I-Algorithm
,	O
and	O
its	O
computational	O
cost	O
is	O
often	O
determined	O
by	O
solving	O
recurrence	O
relations	O
.	O
</s>
<s>
This	O
approach	O
is	O
known	O
as	O
the	O
merge	B-Algorithm
sort	I-Algorithm
algorithm	B-Algorithm
.	O
</s>
<s>
The	O
name	O
"	O
divide	O
and	O
conquer	O
"	O
is	O
sometimes	O
applied	O
to	O
algorithms	O
that	O
reduce	O
each	O
problem	O
to	O
only	O
one	O
sub-problem	O
,	O
such	O
as	O
the	O
binary	O
search	O
algorithm	B-Algorithm
for	O
finding	O
a	O
record	O
in	O
a	O
sorted	B-Algorithm
list	I-Algorithm
(	O
or	O
its	O
analog	O
in	O
numerical	B-General_Concept
computing	I-General_Concept
,	O
the	O
bisection	O
algorithm	B-Algorithm
for	O
root	O
finding	O
)	O
.	O
</s>
<s>
These	O
algorithms	O
can	O
be	O
implemented	O
more	O
efficiently	O
than	O
general	O
divide-and-conquer	O
algorithms	O
;	O
in	O
particular	O
,	O
if	O
they	O
use	O
tail	B-Language
recursion	I-Language
,	O
they	O
can	O
be	O
converted	O
into	O
simple	O
loops	O
.	O
</s>
<s>
Under	O
this	O
broad	O
definition	O
,	O
however	O
,	O
every	O
algorithm	B-Algorithm
that	O
uses	O
recursion	O
or	O
loops	O
could	O
be	O
regarded	O
as	O
a	O
"	O
divide-and-conquer	O
algorithm	B-Algorithm
"	O
.	O
</s>
<s>
An	O
important	O
application	O
of	O
divide	O
and	O
conquer	O
is	O
in	O
optimization	O
,	O
where	O
if	O
the	O
search	O
space	O
is	O
reduced	O
(	O
"	O
pruned	O
"	O
)	O
by	O
a	O
constant	O
factor	O
at	O
each	O
step	O
,	O
the	O
overall	O
algorithm	B-Algorithm
has	O
the	O
same	O
asymptotic	O
complexity	O
as	O
the	O
pruning	O
step	O
,	O
with	O
the	O
constant	O
depending	O
on	O
the	O
pruning	O
factor	O
(	O
by	O
summing	O
the	O
geometric	O
series	O
)	O
;	O
this	O
is	O
known	O
as	O
prune	B-Algorithm
and	I-Algorithm
search	I-Algorithm
.	O
</s>
<s>
Binary	O
search	O
,	O
a	O
decrease-and-conquer	B-Algorithm
algorithm	B-Algorithm
where	O
the	O
subproblems	O
are	O
of	O
roughly	O
half	O
the	O
original	O
size	O
,	O
has	O
a	O
long	O
history	O
.	O
</s>
<s>
While	O
a	O
clear	O
description	O
of	O
the	O
algorithm	B-Algorithm
on	O
computers	O
appeared	O
in	O
1946	O
in	O
an	O
article	O
by	O
John	O
Mauchly	O
,	O
the	O
idea	O
of	O
using	O
a	O
sorted	B-Algorithm
list	I-Algorithm
of	O
items	O
to	O
facilitate	O
searching	O
dates	O
back	O
at	O
least	O
as	O
far	O
as	O
Babylonia	O
in	O
200BC	O
.	O
</s>
<s>
Another	O
ancient	O
decrease-and-conquer	B-Algorithm
algorithm	B-Algorithm
is	O
the	O
Euclidean	O
algorithm	B-Algorithm
to	O
compute	O
the	O
greatest	O
common	O
divisor	O
of	O
two	O
numbers	O
by	O
reducing	O
the	O
numbers	O
to	O
smaller	O
and	O
smaller	O
equivalent	O
subproblems	O
,	O
which	O
dates	O
to	O
several	O
centuries	O
BC	O
.	O
</s>
<s>
An	O
early	O
example	O
of	O
a	O
divide-and-conquer	O
algorithm	B-Algorithm
with	O
multiple	O
subproblems	O
is	O
Gauss	O
's	O
1805	O
description	O
of	O
what	O
is	O
now	O
called	O
the	O
Cooley	B-Algorithm
–	I-Algorithm
Tukey	I-Algorithm
fast	I-Algorithm
Fourier	I-Algorithm
transform	I-Algorithm
(	O
FFT	O
)	O
algorithm	B-Algorithm
,	O
although	O
he	O
did	O
not	O
analyze	B-General_Concept
its	I-General_Concept
operation	I-General_Concept
count	I-General_Concept
quantitatively	O
,	O
and	O
FFTs	O
did	O
not	O
become	O
widespread	O
until	O
they	O
were	O
rediscovered	O
over	O
a	O
century	O
later	O
.	O
</s>
<s>
An	O
early	O
two-subproblem	O
D&C	O
algorithm	B-Algorithm
that	O
was	O
specifically	O
developed	O
for	O
computers	O
and	O
properly	O
analyzed	O
is	O
the	O
merge	B-Algorithm
sort	I-Algorithm
algorithm	B-Algorithm
,	O
invented	O
by	O
John	O
von	O
Neumann	O
in	O
1945	O
.	O
</s>
<s>
Another	O
notable	O
example	O
is	O
the	O
algorithm	B-Algorithm
invented	O
by	O
Anatolii	O
A	O
.	O
Karatsuba	O
in	O
1960	O
that	O
could	O
multiply	O
two	O
n-digit	O
numbers	O
in	O
operations	O
(	O
in	O
Big	O
O	O
notation	O
)	O
.	O
</s>
<s>
This	O
algorithm	B-Algorithm
disproved	O
Andrey	O
Kolmogorov	O
's	O
1956	O
conjecture	O
that	O
operations	O
would	O
be	O
required	O
for	O
that	O
task	O
.	O
</s>
<s>
As	O
another	O
example	O
of	O
a	O
divide-and-conquer	O
algorithm	B-Algorithm
that	O
did	O
not	O
originally	O
involve	O
computers	O
,	O
Donald	O
Knuth	O
gives	O
the	O
method	O
a	O
post	O
office	O
typically	O
uses	O
to	O
route	O
mail	O
:	O
letters	O
are	O
sorted	O
into	O
separate	O
bags	O
for	O
different	O
geographical	O
areas	O
,	O
each	O
of	O
these	O
bags	O
is	O
itself	O
sorted	O
into	O
batches	O
for	O
smaller	O
sub-regions	O
,	O
and	O
so	O
on	O
until	O
they	O
are	O
delivered	O
.	O
</s>
<s>
This	O
is	O
related	O
to	O
a	O
radix	B-Algorithm
sort	I-Algorithm
,	O
described	O
for	O
punch-card	O
sorting	B-Algorithm
machines	O
as	O
early	O
as	O
1929	O
.	O
</s>
<s>
Similarly	O
,	O
decrease	O
and	O
conquer	O
only	O
requires	O
reducing	O
the	O
problem	O
to	O
a	O
single	O
smaller	O
problem	O
,	O
such	O
as	O
the	O
classic	O
Tower	B-Language
of	I-Language
Hanoi	I-Language
puzzle	I-Language
,	O
which	O
reduces	O
moving	O
a	O
tower	O
of	O
height	O
to	O
move	O
a	O
tower	O
of	O
height	O
.	O
</s>
<s>
It	O
was	O
the	O
key	O
,	O
for	O
example	O
,	O
to	O
Karatsuba	O
's	O
fast	B-Algorithm
multiplication	I-Algorithm
method	O
,	O
the	O
quicksort	B-Algorithm
and	O
mergesort	B-Algorithm
algorithms	O
,	O
the	O
Strassen	B-Algorithm
algorithm	I-Algorithm
for	O
matrix	O
multiplication	O
,	O
and	O
fast	O
Fourier	O
transforms	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
(	O
a	O
)	O
the	O
base	O
cases	O
have	O
constant-bounded	O
size	O
,	O
the	O
work	O
of	O
splitting	O
the	O
problem	O
and	O
combining	O
the	O
partial	O
solutions	O
is	O
proportional	O
to	O
the	O
problem	O
's	O
size	O
,	O
and	O
(	O
b	O
)	O
there	O
is	O
a	O
bounded	O
number	O
of	O
sub-problems	O
of	O
size	O
~	O
at	O
each	O
stage	O
,	O
then	O
the	O
cost	O
of	O
the	O
divide-and-conquer	O
algorithm	B-Algorithm
will	O
be	O
.	O
</s>
<s>
Divide-and-conquer	O
algorithms	O
are	O
naturally	O
adapted	O
for	O
execution	O
in	O
multi-processor	O
machines	O
,	O
especially	O
shared-memory	B-Operating_System
systems	O
where	O
the	O
communication	O
of	O
data	O
between	O
processors	O
does	O
not	O
need	O
to	O
be	O
planned	O
in	O
advance	O
because	O
distinct	O
sub-problems	O
can	O
be	O
executed	O
on	O
different	O
processors	O
.	O
</s>
<s>
Divide-and-conquer	O
algorithms	O
naturally	O
tend	O
to	O
make	O
efficient	O
use	O
of	O
memory	B-General_Concept
caches	I-General_Concept
.	O
</s>
<s>
The	O
reason	O
is	O
that	O
once	O
a	O
sub-problem	O
is	O
small	O
enough	O
,	O
it	O
and	O
all	O
its	O
sub-problems	O
can	O
,	O
in	O
principle	O
,	O
be	O
solved	O
within	O
the	O
cache	B-General_Concept
,	O
without	O
accessing	O
the	O
slower	O
main	O
memory	O
.	O
</s>
<s>
An	O
algorithm	B-Algorithm
designed	O
to	O
exploit	O
the	O
cache	B-General_Concept
in	O
this	O
way	O
is	O
called	O
cache-oblivious	B-Application
,	O
because	O
it	O
does	O
not	O
contain	O
the	O
cache	B-General_Concept
size	O
as	O
an	O
explicit	O
parameter	O
.	O
</s>
<s>
Moreover	O
,	O
D&C	O
algorithms	O
can	O
be	O
designed	O
for	O
important	O
algorithms	O
(	O
e.g.	O
,	O
sorting	B-Algorithm
,	O
FFTs	O
,	O
and	O
matrix	O
multiplication	O
)	O
to	O
be	O
optimal	O
cache-oblivious	B-Application
algorithms	I-Application
–	O
they	O
use	O
the	O
cache	B-General_Concept
in	O
a	O
probably	O
optimal	O
way	O
,	O
in	O
an	O
asymptotic	O
sense	O
,	O
regardless	O
of	O
the	O
cache	B-General_Concept
size	O
.	O
</s>
<s>
In	O
contrast	O
,	O
the	O
traditional	O
approach	O
to	O
exploiting	O
the	O
cache	B-General_Concept
is	O
blocking	O
,	O
as	O
in	O
loop	O
nest	O
optimization	O
,	O
where	O
the	O
problem	O
is	O
explicitly	O
divided	O
into	O
chunks	O
of	O
the	O
appropriate	O
size	O
—	O
this	O
can	O
also	O
use	O
the	O
cache	B-General_Concept
optimally	O
,	O
but	O
only	O
when	O
the	O
algorithm	B-Algorithm
is	O
tuned	O
for	O
the	O
specific	O
cache	B-General_Concept
sizes	O
of	O
a	O
particular	O
machine	O
.	O
</s>
<s>
The	O
same	O
advantage	O
exists	O
with	O
regards	O
to	O
other	O
hierarchical	O
storage	O
systems	O
,	O
such	O
as	O
NUMA	B-Operating_System
or	O
virtual	B-Architecture
memory	I-Architecture
,	O
as	O
well	O
as	O
for	O
multiple	O
levels	O
of	O
cache	B-General_Concept
:	O
once	O
a	O
sub-problem	O
is	O
small	O
enough	O
,	O
it	O
can	O
be	O
solved	O
within	O
a	O
given	O
level	O
of	O
the	O
hierarchy	O
,	O
without	O
accessing	O
the	O
higher	O
(	O
slower	O
)	O
levels	O
.	O
</s>
<s>
with	O
floating-point	B-Algorithm
numbers	I-Algorithm
,	O
a	O
divide-and-conquer	O
algorithm	B-Algorithm
may	O
yield	O
more	O
accurate	O
results	O
than	O
a	O
superficially	O
equivalent	O
iterative	O
method	O
.	O
</s>
<s>
For	O
example	O
,	O
one	O
can	O
add	O
N	O
numbers	O
either	O
by	O
a	O
simple	O
loop	O
that	O
adds	O
each	O
datum	O
to	O
a	O
single	O
variable	O
,	O
or	O
by	O
a	O
D&C	O
algorithm	B-Algorithm
called	O
pairwise	B-Algorithm
summation	I-Algorithm
that	O
breaks	O
the	O
data	O
set	O
into	O
two	O
halves	O
,	O
recursively	O
computes	O
the	O
sum	O
of	O
each	O
half	O
,	O
and	O
then	O
adds	O
the	O
two	O
sums	O
.	O
</s>
<s>
In	O
that	O
case	O
,	O
the	O
partial	O
sub-problems	O
leading	O
to	O
the	O
one	O
currently	O
being	O
solved	O
are	O
automatically	O
stored	O
in	O
the	O
procedure	B-General_Concept
call	I-General_Concept
stack	I-General_Concept
.	O
</s>
<s>
Divide-and-conquer	O
algorithms	O
can	O
also	O
be	O
implemented	O
by	O
a	O
non-recursive	O
program	O
that	O
stores	O
the	O
partial	O
sub-problems	O
in	O
some	O
explicit	O
data	O
structure	O
,	O
such	O
as	O
a	O
stack	B-Application
,	O
queue	B-Application
,	O
or	O
priority	B-Application
queue	I-Application
.	O
</s>
<s>
in	O
breadth-first	B-Algorithm
recursion	I-Algorithm
and	O
the	O
branch-and-bound	B-Algorithm
method	O
for	O
function	O
optimization	O
.	O
</s>
<s>
In	O
recursive	O
implementations	O
of	O
D&C	O
algorithms	O
,	O
one	O
must	O
make	O
sure	O
that	O
there	O
is	O
sufficient	O
memory	O
allocated	O
for	O
the	O
recursion	O
stack	B-Application
,	O
otherwise	O
,	O
the	O
execution	O
may	O
fail	O
because	O
of	O
stack	B-Error_Name
overflow	I-Error_Name
.	O
</s>
<s>
For	O
example	O
,	O
the	O
quicksort	B-Algorithm
algorithm	B-Algorithm
can	O
be	O
implemented	O
so	O
that	O
it	O
never	O
requires	O
more	O
than	O
nested	O
recursive	O
calls	O
to	O
sort	O
items	O
.	O
</s>
<s>
Stack	B-Error_Name
overflow	I-Error_Name
may	O
be	O
difficult	O
to	O
avoid	O
when	O
using	O
recursive	O
procedures	O
since	O
many	O
compilers	O
assume	O
that	O
the	O
recursion	O
stack	B-Application
is	O
a	O
contiguous	O
area	O
of	O
memory	O
,	O
and	O
some	O
allocate	O
a	O
fixed	O
amount	O
of	O
space	O
for	O
it	O
.	O
</s>
<s>
Compilers	O
may	O
also	O
save	O
more	O
information	O
in	O
the	O
recursion	O
stack	B-Application
than	O
is	O
strictly	O
necessary	O
,	O
such	O
as	O
return	O
address	O
,	O
unchanging	O
parameters	O
,	O
and	O
the	O
internal	O
variables	O
of	O
the	O
procedure	O
.	O
</s>
<s>
Thus	O
,	O
the	O
risk	O
of	O
stack	B-Error_Name
overflow	I-Error_Name
can	O
be	O
reduced	O
by	O
minimizing	O
the	O
parameters	O
and	O
internal	O
variables	O
of	O
the	O
recursive	O
procedure	O
or	O
by	O
using	O
an	O
explicit	O
stack	B-Application
structure	O
.	O
</s>
<s>
In	O
any	O
recursive	O
algorithm	B-Algorithm
,	O
there	O
is	O
considerable	O
freedom	O
in	O
the	O
choice	O
of	O
the	O
base	O
cases	O
,	O
the	O
small	O
subproblems	O
that	O
are	O
solved	O
directly	O
in	O
order	O
to	O
terminate	O
the	O
recursion	O
.	O
</s>
<s>
For	O
example	O
,	O
an	O
FFT	O
algorithm	B-Algorithm
could	O
stop	O
the	O
recursion	O
when	O
the	O
input	O
is	O
a	O
single	O
sample	O
,	O
and	O
the	O
quicksort	B-Algorithm
list-sorting	O
algorithm	B-Algorithm
could	O
stop	O
when	O
the	O
input	O
is	O
the	O
empty	O
list	O
;	O
in	O
both	O
examples	O
,	O
there	O
is	O
only	O
one	O
base	O
case	O
to	O
consider	O
,	O
and	O
it	O
requires	O
no	O
processing	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
efficiency	O
often	O
improves	O
if	O
the	O
recursion	O
is	O
stopped	O
at	O
relatively	O
large	O
base	O
cases	O
,	O
and	O
these	O
are	O
solved	O
non-recursively	O
,	O
resulting	O
in	O
a	O
hybrid	B-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
A	O
general	O
procedure	O
for	O
a	O
simple	O
hybrid	O
recursive	O
algorithm	B-Algorithm
is	O
short-circuiting	O
the	O
base	O
case	O
,	O
also	O
known	O
as	O
arm's-length	B-Algorithm
recursion	I-Algorithm
.	O
</s>
<s>
Since	O
a	O
D&C	O
algorithm	B-Algorithm
eventually	O
reduces	O
each	O
problem	O
or	O
sub-problem	O
instance	O
to	O
a	O
large	O
number	O
of	O
base	O
instances	O
,	O
these	O
often	O
dominate	O
the	O
overall	O
cost	O
of	O
the	O
algorithm	B-Algorithm
,	O
especially	O
when	O
the	O
splitting/joining	O
overhead	O
is	O
low	O
.	O
</s>
<s>
Note	O
that	O
these	O
considerations	O
do	O
not	O
depend	O
on	O
whether	O
recursion	O
is	O
implemented	O
by	O
the	O
compiler	O
or	O
by	O
an	O
explicit	O
stack	B-Application
.	O
</s>
<s>
Thus	O
,	O
for	O
example	O
,	O
many	O
library	O
implementations	O
of	O
quicksort	B-Algorithm
will	O
switch	O
to	O
a	O
simple	O
loop-based	O
insertion	B-Algorithm
sort	I-Algorithm
(	O
or	O
similar	O
)	O
algorithm	B-Algorithm
once	O
the	O
number	O
of	O
items	O
to	O
be	O
sorted	O
is	O
sufficiently	O
small	O
.	O
</s>
<s>
Note	O
that	O
,	O
if	O
the	O
empty	O
list	O
were	O
the	O
only	O
base	O
case	O
,	O
sorting	B-Algorithm
a	O
list	O
with	O
entries	O
would	O
entail	O
maximally	O
quicksort	B-Algorithm
calls	O
that	O
would	O
do	O
nothing	O
but	O
return	O
immediately	O
.	O
</s>
<s>
Increasing	O
the	O
base	O
cases	O
to	O
lists	O
of	O
size	O
2	O
or	O
less	O
will	O
eliminate	O
most	O
of	O
those	O
do-nothing	O
calls	O
,	O
and	O
more	O
generally	O
a	O
base	O
case	O
larger	O
than	O
2	O
is	O
typically	O
used	O
to	O
reduce	O
the	O
fraction	O
of	O
time	O
spent	O
in	O
function-call	O
overhead	O
or	O
stack	B-Application
manipulation	O
.	O
</s>
<s>
Alternatively	O
,	O
one	O
can	O
employ	O
large	O
base	O
cases	O
that	O
still	O
use	O
a	O
divide-and-conquer	O
algorithm	B-Algorithm
,	O
but	O
implement	O
the	O
algorithm	B-Algorithm
for	O
predetermined	O
set	O
of	O
fixed	O
sizes	O
where	O
the	O
algorithm	B-Algorithm
can	O
be	O
completely	O
unrolled	B-Operating_System
into	O
code	O
that	O
has	O
no	O
recursion	O
,	O
loops	O
,	O
or	O
conditionals	B-Language
(	O
related	O
to	O
the	O
technique	O
of	O
partial	O
evaluation	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
this	O
approach	O
is	O
used	O
in	O
some	O
efficient	O
FFT	O
implementations	O
,	O
where	O
the	O
base	O
cases	O
are	O
unrolled	B-Operating_System
implementations	O
of	O
divide-and-conquer	O
FFT	O
algorithms	O
for	O
a	O
set	O
of	O
fixed	O
sizes	O
.	O
</s>
<s>
Followed	O
to	O
the	O
limit	O
,	O
it	O
leads	O
to	O
bottom-up	O
divide-and-conquer	O
algorithms	O
such	O
as	O
dynamic	B-Algorithm
programming	I-Algorithm
.	O
</s>
