<s>
In	O
number	O
theory	O
and	O
computer	B-General_Concept
science	I-General_Concept
,	O
the	O
partition	B-Algorithm
problem	I-Algorithm
,	O
or	O
number	B-Algorithm
partitioning	I-Algorithm
,	O
is	O
the	O
task	O
of	O
deciding	O
whether	O
a	O
given	O
multiset	B-Language
S	O
of	O
positive	O
integers	O
can	O
be	O
partitioned	O
into	O
two	O
subsets	O
S1	O
and	O
S2	O
such	O
that	O
the	O
sum	O
of	O
the	O
numbers	O
in	O
S1	O
equals	O
the	O
sum	O
of	O
the	O
numbers	O
in	O
S2	O
.	O
</s>
<s>
Although	O
the	O
partition	B-Algorithm
problem	I-Algorithm
is	O
NP-complete	O
,	O
there	O
is	O
a	O
pseudo-polynomial	B-Algorithm
time	I-Algorithm
dynamic	B-Algorithm
programming	I-Algorithm
solution	O
,	O
and	O
there	O
are	O
heuristics	B-Algorithm
that	O
solve	O
the	O
problem	O
in	O
many	O
instances	O
,	O
either	O
optimally	O
or	O
approximately	O
.	O
</s>
<s>
There	O
is	O
an	O
optimization	O
version	O
of	O
the	O
partition	B-Algorithm
problem	I-Algorithm
,	O
which	O
is	O
to	O
partition	O
the	O
multiset	B-Language
S	O
into	O
two	O
subsets	O
S1	O
,	O
S2	O
such	O
that	O
the	O
difference	O
between	O
the	O
sum	O
of	O
elements	O
in	O
S1	O
and	O
the	O
sum	O
of	O
elements	O
in	O
S2	O
is	O
minimized	O
.	O
</s>
<s>
The	O
partition	B-Algorithm
problem	I-Algorithm
is	O
a	O
special	O
case	O
of	O
two	O
related	O
problems	O
:	O
</s>
<s>
In	O
the	O
subset	B-Algorithm
sum	I-Algorithm
problem	I-Algorithm
,	O
the	O
goal	O
is	O
to	O
find	O
a	O
subset	O
of	O
S	O
whose	O
sum	O
is	O
a	O
certain	O
target	O
number	O
T	O
given	O
as	O
input	O
(	O
the	O
partition	B-Algorithm
problem	I-Algorithm
is	O
the	O
special	O
case	O
in	O
which	O
T	O
is	O
half	O
the	O
sum	O
of	O
S	O
)	O
.	O
</s>
<s>
In	O
multiway	B-Algorithm
number	I-Algorithm
partitioning	I-Algorithm
,	O
there	O
is	O
an	O
integer	O
parameter	O
k	O
,	O
and	O
the	O
goal	O
is	O
to	O
decide	O
whether	O
S	O
can	O
be	O
partitioned	O
into	O
k	O
subsets	O
of	O
equal	O
sum	O
(	O
the	O
partition	B-Algorithm
problem	I-Algorithm
is	O
the	O
special	O
case	O
in	O
which	O
k	O
=	O
2	O
)	O
.	O
</s>
<s>
However	O
,	O
it	O
is	O
quite	O
different	O
than	O
the	O
3-partition	B-Algorithm
problem	I-Algorithm
:	O
in	O
that	O
problem	O
,	O
the	O
number	O
of	O
subsets	O
is	O
not	O
fixed	O
in	O
advance	O
–	O
it	O
should	O
be	O
|S|	O
/3	O
,	O
where	O
each	O
subset	O
must	O
have	O
exactly	O
3	O
elements	O
.	O
</s>
<s>
3-partition	B-Algorithm
is	O
much	O
harder	O
than	O
partition	O
–	O
it	O
has	O
no	O
pseudo-polynomial	B-Algorithm
time	I-Algorithm
algorithm	O
unless	O
P	O
=	O
NP	O
.	O
</s>
<s>
Given	O
S	O
=	O
{3,1,1,2,2,1},	O
a	O
valid	O
solution	O
to	O
the	O
partition	B-Algorithm
problem	I-Algorithm
is	O
the	O
two	O
sets	O
S1	O
=	O
 { 1 , 1 , 1 , 2 } 	O
and	O
S2	O
=	O
 { 2 , 3 } 	O
.	O
</s>
<s>
Not	O
every	O
multiset	B-Language
of	O
positive	O
integers	O
has	O
a	O
partition	O
into	O
two	O
subsets	O
with	O
equal	O
sum	O
.	O
</s>
<s>
The	O
partition	B-Algorithm
problem	I-Algorithm
is	O
NP	O
hard	O
.	O
</s>
<s>
This	O
can	O
be	O
proved	O
by	O
reduction	O
from	O
the	O
subset	B-Algorithm
sum	I-Algorithm
problem	I-Algorithm
.	O
</s>
<s>
As	O
mentioned	O
above	O
,	O
the	O
partition	B-Algorithm
problem	I-Algorithm
is	O
a	O
special	O
case	O
of	O
multiway-partitioning	O
and	O
of	O
subset-sum	B-Algorithm
.	O
</s>
<s>
Algorithms	O
developed	O
for	O
multiway	B-Algorithm
number	I-Algorithm
partitioning	I-Algorithm
include	O
:	O
</s>
<s>
Greedy	B-Algorithm
number	I-Algorithm
partitioning	I-Algorithm
–	O
loops	O
over	O
the	O
numbers	O
,	O
and	O
puts	O
each	O
number	O
in	O
the	O
set	O
whose	O
current	O
sum	O
is	O
smallest	O
.	O
</s>
<s>
Largest	B-Algorithm
Differencing	I-Algorithm
Method	I-Algorithm
(	O
also	O
called	O
the	O
Karmarkar	B-Algorithm
–	I-Algorithm
Karp	I-Algorithm
algorithm	I-Algorithm
)	O
sorts	O
the	O
numbers	O
in	O
descending	O
order	O
and	O
repeatedly	O
replaces	O
numbers	O
by	O
their	O
differences	O
.	O
</s>
<s>
The	O
Multifit	B-Algorithm
algorithm	I-Algorithm
uses	O
binary	O
search	O
combined	O
with	O
an	O
algorithm	O
for	O
bin	O
packing	O
.	O
</s>
<s>
The	O
subset	B-Algorithm
sum	I-Algorithm
problem	I-Algorithm
has	O
an	O
FPTAS	O
which	O
can	O
be	O
used	O
for	O
the	O
partition	B-Algorithm
problem	I-Algorithm
as	O
well	O
,	O
by	O
setting	O
the	O
target	O
sum	O
to	O
sum(S )	O
/2	O
.	O
</s>
<s>
There	O
are	O
exact	B-Algorithm
algorithms	I-Algorithm
,	O
that	O
always	O
find	O
the	O
optimal	O
partition	O
.	O
</s>
<s>
Algorithms	O
developed	O
for	O
multiway	B-Algorithm
number	I-Algorithm
partitioning	I-Algorithm
include	O
:	O
</s>
<s>
The	O
pseudopolynomial	B-Algorithm
time	I-Algorithm
number	I-Algorithm
partitioning	I-Algorithm
takes	O
memory	O
,	O
where	O
is	O
the	O
largest	O
number	O
in	O
the	O
input	O
.	O
</s>
<s>
Traversing	O
the	O
tree	O
in	O
depth-first	B-Algorithm
order	O
requires	O
only	O
space	O
,	O
but	O
might	O
take	O
time	O
.	O
</s>
<s>
The	O
runtime	O
can	O
be	O
improved	O
by	O
using	O
a	O
greedy	O
heuristic	B-Algorithm
:	O
in	O
each	O
level	O
,	O
develop	O
first	O
the	O
branch	O
in	O
which	O
the	O
current	O
number	O
is	O
put	O
in	O
the	O
set	O
with	O
the	O
smallest	O
sum	O
.	O
</s>
<s>
This	O
algorithm	O
finds	O
first	O
the	O
solution	O
found	O
by	O
greedy	B-Algorithm
number	I-Algorithm
partitioning	I-Algorithm
,	O
but	O
then	O
proceeds	O
to	O
look	O
for	O
better	O
solutions	O
.	O
</s>
<s>
Some	O
variations	O
of	O
this	O
idea	O
are	O
fully	O
polynomial-time	B-Algorithm
approximation	I-Algorithm
schemes	I-Algorithm
for	O
the	O
subset-sum	B-Algorithm
problem	I-Algorithm
,	O
and	O
hence	O
for	O
the	O
partition	B-Algorithm
problem	I-Algorithm
as	O
well	O
.	O
</s>
<s>
The	O
Complete	B-Algorithm
Karmarkar-Karp	I-Algorithm
algorithm	O
(	O
CKK	O
)	O
considers	O
all	O
partitions	O
by	O
constructing	O
a	O
binary	O
tree	O
.	O
</s>
<s>
This	O
algorithm	O
finds	O
first	O
the	O
solution	O
found	O
by	O
the	O
largest	B-Algorithm
differencing	I-Algorithm
method	I-Algorithm
,	O
but	O
then	O
proceeds	O
to	O
find	O
better	O
solutions	O
.	O
</s>
<s>
In	O
practice	O
,	O
problems	O
of	O
arbitrary	O
size	O
can	O
be	O
solved	O
by	O
CKK	O
if	O
the	O
numbers	O
have	O
at	O
most	O
12	O
significant	B-Architecture
digits	I-Architecture
.	O
</s>
<s>
CKK	O
can	O
also	O
run	O
as	O
an	O
anytime	B-Algorithm
algorithm	I-Algorithm
:	O
it	O
finds	O
the	O
KK	O
solution	O
first	O
,	O
and	O
then	O
finds	O
progressively	O
better	O
solutions	O
as	O
time	O
allows	O
(	O
possibly	O
requiring	O
exponential	O
time	O
to	O
reach	O
optimality	O
,	O
for	O
the	O
worst	O
instances	O
)	O
.	O
</s>
<s>
Algorithms	O
developed	O
for	O
subset	B-Algorithm
sum	I-Algorithm
include	O
:	O
</s>
<s>
Howgrave-Graham	O
and	O
Joux	O
–	O
runs	O
in	O
time	O
,	O
but	O
it	O
is	O
a	O
randomized	B-General_Concept
algorithm	I-General_Concept
that	O
only	O
solves	O
the	O
decision	O
problem	O
(	O
not	O
the	O
optimization	O
problem	O
)	O
.	O
</s>
<s>
See	O
also	O
Balanced	B-Algorithm
number	I-Algorithm
partitioning	I-Algorithm
.	O
</s>
<s>
One	O
application	O
of	O
the	O
partition	B-Algorithm
problem	I-Algorithm
is	O
for	O
manipulation	O
of	O
elections	O
.	O
</s>
<s>
If	O
the	O
votes	O
are	O
weighted	O
,	O
then	O
the	O
problem	O
can	O
be	O
reduced	O
to	O
the	O
partition	B-Algorithm
problem	I-Algorithm
,	O
and	O
thus	O
it	O
can	O
be	O
solved	O
efficiently	O
using	O
CKK	O
.	O
</s>
