<s>
The	O
knapsack	B-Algorithm
problem	I-Algorithm
is	O
the	O
following	O
problem	O
in	O
combinatorial	O
optimization	O
:	O
</s>
<s>
The	O
problem	O
often	O
arises	O
in	O
resource	B-Algorithm
allocation	I-Algorithm
where	O
the	O
decision-makers	O
have	O
to	O
choose	O
from	O
a	O
set	O
of	O
non-divisible	O
projects	O
or	O
tasks	O
under	O
a	O
fixed	O
budget	O
or	O
time	O
constraint	O
,	O
respectively	O
.	O
</s>
<s>
The	O
knapsack	B-Algorithm
problem	I-Algorithm
has	O
been	O
studied	O
for	O
more	O
than	O
a	O
century	O
,	O
with	O
early	O
works	O
dating	O
as	O
far	O
back	O
as	O
1897	O
.	O
</s>
<s>
The	O
name	O
"	O
knapsack	B-Algorithm
problem	I-Algorithm
"	O
dates	O
back	O
to	O
the	O
early	O
works	O
of	O
the	O
mathematician	O
Tobias	O
Dantzig	O
(	O
18841956	O
)	O
,	O
and	O
refers	O
to	O
the	O
commonplace	O
problem	O
of	O
packing	O
the	O
most	O
valuable	O
or	O
useful	O
items	O
without	O
overloading	O
the	O
luggage	O
.	O
</s>
<s>
Knapsack	B-Algorithm
problems	I-Algorithm
appear	O
in	O
real-world	O
decision-making	O
processes	O
in	O
a	O
wide	O
variety	O
of	O
fields	O
,	O
such	O
as	O
finding	O
the	O
least	O
wasteful	O
way	O
to	O
cut	O
raw	O
materials	O
,	O
selection	O
of	O
investments	O
and	O
portfolios	O
,	O
selection	O
of	O
assets	O
for	O
asset-backed	O
securitization	O
,	O
and	O
generating	O
keys	O
for	O
the	O
Merkle	B-Algorithm
–	I-Algorithm
Hellman	I-Algorithm
and	O
other	O
knapsack	B-General_Concept
cryptosystems	I-General_Concept
.	O
</s>
<s>
A	O
1999	O
study	O
of	O
the	O
Stony	O
Brook	O
University	O
Algorithm	O
Repository	O
showed	O
that	O
,	O
out	O
of	O
75	O
algorithmic	O
problems	O
related	O
to	O
the	O
field	O
of	O
combinatorial	O
algorithms	O
and	O
algorithm	O
engineering	O
,	O
the	O
knapsack	B-Algorithm
problem	I-Algorithm
was	O
the	O
19th	O
most	O
popular	O
and	O
the	O
third	O
most	O
needed	O
after	O
suffix	B-Architecture
trees	I-Architecture
and	O
the	O
bin	O
packing	O
problem	O
.	O
</s>
<s>
The	O
most	O
common	O
problem	O
being	O
solved	O
is	O
the	O
0-1	B-Algorithm
knapsack	I-Algorithm
problem	I-Algorithm
,	O
which	O
restricts	O
the	O
number	O
of	O
copies	O
of	O
each	O
kind	O
of	O
item	O
to	O
zero	O
or	O
one	O
.	O
</s>
<s>
The	O
bounded	O
knapsack	B-Algorithm
problem	I-Algorithm
(	O
BKP	O
)	O
removes	O
the	O
restriction	O
that	O
there	O
is	O
only	O
one	O
of	O
each	O
item	O
,	O
but	O
restricts	O
the	O
number	O
of	O
copies	O
of	O
each	O
kind	O
of	O
item	O
to	O
a	O
maximum	O
non-negative	O
integer	O
value	O
:	O
</s>
<s>
The	O
unbounded	B-Algorithm
knapsack	I-Algorithm
problem	I-Algorithm
(	O
UKP	O
)	O
places	O
no	O
upper	O
bound	O
on	O
the	O
number	O
of	O
copies	O
of	O
each	O
kind	O
of	O
item	O
and	O
can	O
be	O
formulated	O
as	O
above	O
except	O
that	O
the	O
only	O
restriction	O
on	O
is	O
that	O
it	O
is	O
a	O
non-negative	O
integer	O
.	O
</s>
<s>
One	O
example	O
of	O
the	O
unbounded	B-Algorithm
knapsack	I-Algorithm
problem	I-Algorithm
is	O
given	O
using	O
the	O
figure	O
shown	O
at	O
the	O
beginning	O
of	O
this	O
article	O
and	O
the	O
text	O
"	O
if	O
any	O
number	O
of	O
each	O
box	O
is	O
available	O
"	O
in	O
the	O
caption	O
of	O
that	O
figure	O
.	O
</s>
<s>
The	O
knapsack	B-Algorithm
problem	I-Algorithm
is	O
interesting	O
from	O
the	O
perspective	O
of	O
computer	O
science	O
for	O
many	O
reasons	O
:	O
</s>
<s>
The	O
decision	O
problem	O
form	O
of	O
the	O
knapsack	B-Algorithm
problem	I-Algorithm
(	O
Can	O
a	O
value	O
of	O
at	O
least	O
V	O
be	O
achieved	O
without	O
exceeding	O
the	O
weight	O
W	O
?	O
)	O
</s>
<s>
There	O
is	O
a	O
pseudo-polynomial	B-Algorithm
time	I-Algorithm
algorithm	O
using	O
dynamic	B-Algorithm
programming	I-Algorithm
.	O
</s>
<s>
There	O
is	O
a	O
fully	B-Algorithm
polynomial-time	I-Algorithm
approximation	I-Algorithm
scheme	I-Algorithm
,	O
which	O
uses	O
the	O
pseudo-polynomial	B-Algorithm
time	I-Algorithm
algorithm	O
as	O
a	O
subroutine	O
,	O
described	O
below	O
.	O
</s>
<s>
One	O
theme	O
in	O
research	O
literature	O
is	O
to	O
identify	O
what	O
the	O
"	O
hard	O
"	O
instances	O
of	O
the	O
knapsack	B-Algorithm
problem	I-Algorithm
look	O
like	O
,	O
or	O
viewed	O
another	O
way	O
,	O
to	O
identify	O
what	O
properties	O
of	O
instances	O
in	O
practice	O
might	O
make	O
them	O
more	O
amenable	O
than	O
their	O
worst-case	O
NP-complete	O
behaviour	O
suggests	O
.	O
</s>
<s>
The	O
goal	O
in	O
finding	O
these	O
"	O
hard	O
"	O
instances	O
is	O
for	O
their	O
use	O
in	O
public	B-Application
key	I-Application
cryptography	I-Application
systems	O
,	O
such	O
as	O
the	O
Merkle-Hellman	B-Algorithm
knapsack	I-Algorithm
cryptosystem	I-Algorithm
.	O
</s>
<s>
Furthermore	O
,	O
notable	O
is	O
the	O
fact	O
that	O
the	O
hardness	O
of	O
the	O
knapsack	B-Algorithm
problem	I-Algorithm
depends	O
on	O
the	O
form	O
of	O
the	O
input	O
.	O
</s>
<s>
However	O
,	O
in	O
the	O
case	O
of	O
rational	O
weights	O
and	O
profits	O
it	O
still	O
admits	O
a	O
fully	B-Algorithm
polynomial-time	I-Algorithm
approximation	I-Algorithm
scheme	I-Algorithm
.	O
</s>
<s>
Several	O
algorithms	O
are	O
available	O
to	O
solve	O
knapsack	B-Algorithm
problems	I-Algorithm
,	O
based	O
on	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
approach	O
,	O
the	O
branch	B-Algorithm
and	I-Algorithm
bound	I-Algorithm
approach	O
or	O
hybridizations	B-Algorithm
of	O
both	O
approaches	O
.	O
</s>
<s>
The	O
unbounded	B-Algorithm
knapsack	I-Algorithm
problem	I-Algorithm
(	O
UKP	O
)	O
places	O
no	O
restriction	O
on	O
the	O
number	O
of	O
copies	O
of	O
each	O
kind	O
of	O
item	O
.	O
</s>
<s>
Since	O
the	O
calculation	O
of	O
each	O
involves	O
examining	O
at	O
most	O
items	O
,	O
and	O
there	O
are	O
at	O
most	O
values	O
of	O
to	O
calculate	O
,	O
the	O
running	O
time	O
of	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
solution	O
is	O
.	O
</s>
<s>
Even	O
if	O
P≠NP	O
,	O
the	O
complexity	O
does	O
not	O
contradict	O
the	O
fact	O
that	O
the	O
knapsack	B-Algorithm
problem	I-Algorithm
is	O
NP-complete	O
,	O
since	O
,	O
unlike	O
,	O
is	O
not	O
polynomial	O
in	O
the	O
length	O
of	O
the	O
input	O
to	O
the	O
problem	O
.	O
</s>
<s>
However	O
,	O
since	O
this	O
runtime	O
is	O
pseudopolynomial	B-Algorithm
,	O
this	O
makes	O
the	O
(	O
decision	O
version	O
of	O
the	O
)	O
knapsack	B-Algorithm
problem	I-Algorithm
a	O
weakly	O
NP-complete	O
problem	O
.	O
</s>
<s>
A	O
similar	O
dynamic	B-Algorithm
programming	I-Algorithm
solution	O
for	O
the	O
0-1	B-Algorithm
knapsack	I-Algorithm
problem	I-Algorithm
also	O
runs	O
in	O
pseudo-polynomial	B-Algorithm
time	I-Algorithm
.	O
</s>
<s>
Another	O
algorithm	O
for	O
0-1	O
knapsack	O
,	O
discovered	O
in	O
1974	O
and	O
sometimes	O
called	O
"	O
meet-in-the-middle	O
"	O
due	O
to	O
parallels	O
to	O
a	O
similarly	O
named	O
algorithm	O
in	O
cryptography	O
,	O
is	O
exponential	O
in	O
the	O
number	O
of	O
different	O
items	O
but	O
may	O
be	O
preferable	O
to	O
the	O
DP	O
algorithm	O
when	O
is	O
large	O
compared	O
to	O
n	O
.	O
In	O
particular	O
,	O
if	O
the	O
are	O
nonnegative	O
but	O
not	O
integers	O
,	O
we	O
could	O
still	O
use	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
algorithm	O
by	O
scaling	O
and	O
rounding	O
(	O
i.e.	O
</s>
<s>
As	O
with	O
the	O
meet	O
in	O
the	O
middle	O
attack	O
in	O
cryptography	O
,	O
this	O
improves	O
on	O
the	O
runtime	O
of	O
a	O
naive	O
brute	O
force	O
approach	O
(	O
examining	O
all	O
subsets	O
of	O
)	O
,	O
at	O
the	O
cost	O
of	O
using	O
exponential	O
rather	O
than	O
constant	O
space	O
(	O
see	O
also	O
baby-step	B-Language
giant-step	I-Language
)	O
.	O
</s>
<s>
The	O
current	O
state	O
of	O
the	O
art	O
improvement	O
to	O
the	O
meet-in-the-middle	O
algorithm	O
,	O
using	O
insights	O
from	O
Schroeppel	O
and	O
Shamir	O
's	O
Algorithm	O
for	O
Subset	B-Algorithm
Sum	I-Algorithm
,	O
provides	O
as	O
a	O
corollary	O
a	O
randomized	O
algorithm	O
for	O
Knapsack	O
which	O
preserves	O
the	O
(	O
up	O
to	O
polynomial	O
factors	O
)	O
running	O
time	O
and	O
reduces	O
the	O
space	O
requirements	O
to	O
(	O
see	O
Corollary	O
1.4	O
)	O
.	O
</s>
<s>
The	O
knapsack	B-Algorithm
problem	I-Algorithm
,	O
though	O
NP-Hard	O
,	O
is	O
one	O
of	O
a	O
collection	O
of	O
algorithms	O
that	O
can	O
still	O
be	O
approximated	O
to	O
any	O
specified	O
degree	O
.	O
</s>
<s>
This	O
means	O
that	O
the	O
problem	O
has	O
a	O
polynomial	B-Algorithm
time	I-Algorithm
approximation	I-Algorithm
scheme	I-Algorithm
.	O
</s>
<s>
To	O
be	O
exact	O
,	O
the	O
knapsack	B-Algorithm
problem	I-Algorithm
has	O
a	O
fully	B-Algorithm
polynomial	I-Algorithm
time	I-Algorithm
approximation	I-Algorithm
scheme	I-Algorithm
(	O
FPTAS	B-Algorithm
)	O
.	O
</s>
<s>
George	O
Dantzig	O
proposed	O
a	O
greedy	B-Algorithm
approximation	B-Algorithm
algorithm	I-Algorithm
to	O
solve	O
the	O
unbounded	B-Algorithm
knapsack	I-Algorithm
problem	I-Algorithm
.	O
</s>
<s>
Provided	O
that	O
there	O
is	O
an	O
unlimited	O
supply	O
of	O
each	O
kind	O
of	O
item	O
,	O
if	O
is	O
the	O
maximum	O
value	O
of	O
items	O
that	O
fit	O
into	O
the	O
sack	O
,	O
then	O
the	O
greedy	B-Algorithm
algorithm	I-Algorithm
is	O
guaranteed	O
to	O
achieve	O
at	O
least	O
a	O
value	O
of	O
.	O
</s>
<s>
Since	O
provides	O
an	O
upper	O
bound	O
for	O
the	O
LP	B-Algorithm
relaxation	I-Algorithm
of	O
the	O
problem	O
,	O
one	O
of	O
the	O
sets	O
must	O
have	O
value	O
at	O
least	O
;	O
we	O
thus	O
return	O
whichever	O
of	O
and	O
has	O
better	O
value	O
to	O
obtain	O
a	O
-approximation	O
.	O
</s>
<s>
The	O
fully	B-Algorithm
polynomial	I-Algorithm
time	I-Algorithm
approximation	I-Algorithm
scheme	I-Algorithm
(	O
FPTAS	B-Algorithm
)	O
for	O
the	O
knapsack	B-Algorithm
problem	I-Algorithm
takes	O
advantage	O
of	O
the	O
fact	O
that	O
the	O
reason	O
the	O
problem	O
has	O
no	O
known	O
polynomial	O
time	O
solutions	O
is	O
because	O
the	O
profits	O
associated	O
with	O
the	O
items	O
are	O
not	O
restricted	O
.	O
</s>
<s>
Solving	O
the	O
unbounded	B-Algorithm
knapsack	I-Algorithm
problem	I-Algorithm
can	O
be	O
made	O
easier	O
by	O
throwing	O
away	O
items	O
which	O
will	O
never	O
be	O
needed	O
.	O
</s>
<s>
(	O
Note	O
that	O
this	O
does	O
not	O
apply	O
to	O
bounded	O
knapsack	B-Algorithm
problems	I-Algorithm
,	O
since	O
we	O
may	O
have	O
already	O
used	O
up	O
the	O
items	O
in	O
.	O
)	O
</s>
<s>
Verifying	O
this	O
dominance	O
is	O
computationally	O
hard	O
,	O
so	O
it	O
can	O
only	O
be	O
used	O
with	O
a	O
dynamic	B-Algorithm
programming	I-Algorithm
approach	O
.	O
</s>
<s>
There	O
are	O
many	O
variations	O
of	O
the	O
knapsack	B-Algorithm
problem	I-Algorithm
that	O
have	O
arisen	O
from	O
the	O
vast	O
number	O
of	O
applications	O
of	O
the	O
basic	O
problem	O
.	O
</s>
<s>
Multi-dimensional	O
knapsack	O
is	O
computationally	O
harder	O
than	O
knapsack	O
;	O
even	O
for	O
,	O
the	O
problem	O
does	O
not	O
have	O
EPTAS	B-Algorithm
unless	O
PNP	O
.	O
</s>
<s>
This	O
variation	O
is	O
used	O
in	O
many	O
loading	O
and	O
scheduling	O
problems	O
in	O
Operations	O
Research	O
and	O
has	O
a	O
Polynomial-time	B-Algorithm
approximation	I-Algorithm
scheme	I-Algorithm
.	O
</s>
<s>
The	O
quadratic	O
knapsack	B-Algorithm
problem	I-Algorithm
maximizes	O
a	O
quadratic	O
objective	O
function	O
subject	O
to	O
binary	O
and	O
linear	O
capacity	O
constraints	O
.	O
</s>
<s>
The	O
subset	B-Algorithm
sum	I-Algorithm
problem	I-Algorithm
is	O
a	O
special	O
case	O
of	O
the	O
decision	O
and	O
0-1	O
problems	O
where	O
each	O
kind	O
of	O
item	O
,	O
the	O
weight	O
equals	O
the	O
value	O
:	O
.	O
</s>
<s>
In	O
the	O
field	O
of	O
cryptography	O
,	O
the	O
term	O
knapsack	B-Algorithm
problem	I-Algorithm
is	O
often	O
used	O
to	O
refer	O
specifically	O
to	O
the	O
subset	B-Algorithm
sum	I-Algorithm
problem	I-Algorithm
and	O
is	O
commonly	O
known	O
as	O
one	O
of	O
Karp	O
's	O
21	O
NP-complete	O
problems	O
.	O
</s>
<s>
The	O
generalization	O
of	O
subset	B-Algorithm
sum	I-Algorithm
problem	I-Algorithm
is	O
called	O
multiple	O
subset-sum	B-Algorithm
problem	I-Algorithm
,	O
in	O
which	O
multiple	O
bins	O
exist	O
with	O
the	O
same	O
capacity	O
.	O
</s>
<s>
It	O
has	O
been	O
shown	O
that	O
the	O
generalization	O
does	O
not	O
have	O
an	O
FPTAS	B-Algorithm
.	O
</s>
<s>
In	O
the	O
geometric	O
knapsack	B-Algorithm
problem	I-Algorithm
,	O
there	O
is	O
a	O
set	O
of	O
rectangles	O
with	O
different	O
values	O
,	O
and	O
a	O
rectangular	O
knapsack	O
.	O
</s>
