SlideShare une entreprise Scribd logo
1  sur  129
Télécharger pour lire hors ligne
Advanced Algorithms – COMS31900
Approximation algorithms part one
Constant factor approximations
Benjamin Sach
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
(this second part is the definition of NP-hard)
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
(this second part is the definition of NP-hard)
‘yes/no’ problems
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
(this second part is the definition of NP-hard)
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
(this second part is the definition of NP-hard)
we can solve B
using A
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
(this second part is the definition of NP-hard)
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
If we could solve A quickly we could solve every problem in NP quickly
(this second part is the definition of NP-hard)
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
If we could solve A quickly we could solve every problem in NP quickly
They are the ‘hardest’ problems in NP
(this second part is the definition of NP-hard)
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
If we could solve A quickly we could solve every problem in NP quickly
They are the ‘hardest’ problems in NP
(this second part is the definition of NP-hard)
that you can’t solve them in polynomial time (i.e. that P = NP)
Most computer scientists (I’ve met) believe
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
If we could solve A quickly we could solve every problem in NP quickly
They are the ‘hardest’ problems in NP
(this second part is the definition of NP-hard)
A polynomial time algorithm for an
NP-complete problem is worth
(a lot more than) a million dollars
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
If we could solve A quickly we could solve every problem in NP quickly
They are the ‘hardest’ problems in NP
(this second part is the definition of NP-hard)
NP-completeness recap
A problem A is NP-complete if
NP is the class of decision problems we can
check the answer to in polynomial time
A is in NP
Every B in NP has a polynomial time reduction to A
If we could solve A quickly we could solve every problem in NP quickly
They are the ‘hardest’ problems in NP
So if a problem is NP-complete, we give up right?
(this second part is the definition of NP-hard)
Bin packing
1
1
4/8 4/8
7/8
3/82/82/8
Bin packing
Bins
1
1
4/8 4/8
7/8
3/82/82/8
Bin packing
Bins
1
Items
1
4/8 4/8
7/8
3/82/82/8
Bin packing
Bins
1
Items
1
4/8 4/8
7/8
3/82/82/8
0 < |Item| 1
Bin packing
Bins
1
Items
1
4/8 4/8
7/8
3/82/82/8
0 < |Item| 1
I is the sum of all item sizes
Bin packing
Bins
1
Items
1
4/8 4/8
7/8
3/82/82/8
0 < |Item| 1
|Bin| = 1 and there is an unlimited number of bins. . .
I is the sum of all item sizes
Bin packing
1
1
4/8 4/8
7/8
3/82/82/8
Problem pack all items into the fewest possible bins
Bin packing
1
1
4/8 4/8
7/8
3/82/82/8
Problem pack all items into the fewest possible bins
This is an example of an optimisation problem
Bin packing
1
1
Problem pack all items into the fewest possible bins
4/8 4/8
7/8
2/82/8
3/8
This is an example of an optimisation problem
Bin packing
1
1
4/8 4/8
7/8
3/82/82/8
Problem pack all items into the fewest possible bins
This is an example of an optimisation problem
Bin packing
1
1
Problem pack all items into the fewest possible bins
4/8
4/8
7/8
2/8
2/8
3/8
This is an example of an optimisation problem
Bin packing
1
1
Problem pack all items into the fewest possible bins
4/8
4/8
7/8
2/8
2/8
3/8
Bin packing
1
1
Problem pack all items into the fewest possible bins
4/8
4/8
7/8
2/8
2/8
3/8
The BINPACKING problem is known to be NP-hard
Bin packing
1
1
Problem pack all items into the fewest possible bins
4/8
4/8
7/8
2/8
2/8
3/8
The BINPACKING problem is known to be NP-hard
and the decision version. . . “Can you pack the items into at most k bins?”
is NP-complete
Bin packing
1
1
Problem pack all items into the fewest possible bins
4/8
4/8
7/8
2/8
2/8
3/8
The BINPACKING problem is known to be NP-hard
and the decision version. . . “Can you pack the items into at most k bins?”
is NP-complete
In the decision version,
k is part of the input
Bin packing
1
1
Problem pack all items into the fewest possible bins
4/8
4/8
7/8
2/8
2/8
3/8
The BINPACKING problem is known to be NP-hard
Bin packing
1
1
Problem pack all items into the fewest possible bins
4/8
4/8
7/8
2/8
2/8
3/8
The BINPACKING problem is known to be NP-hard
but fortunately we can approximate
Next fit
1
1
4/8 4/8
7/8
3/82/82/8
If item i fits into bin j: pack it, i++; else j++;
Next fit
1
1
4/8 4/8
7/8
3/82/82/8
If item i fits into bin j: pack it, i++; else j++;
Next fit
1
1
4/8
7/8
3/82/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
Next fit
1
1
4/8
7/8
3/82/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
Next fit
1
1
4/8
7/8
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
Next fit
1
1
4/8
7/8
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
Next fit
1
1
4/8
7/8
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
Next fit
1
1
7/8
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
Next fit
1
1
7/8
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
Next fit
1
1
7/8
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
Next fit
1
1
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
7/8
Next fit
1
1
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
7/8
Next fit
1
1
3/82/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
7/8
Next fit
1
1
3/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
7/8
2/8
Next fit
1
1
3/8
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
7/8
2/8
Next fit
1
1
If item i fits into bin j: pack it, i++; else j++;
4/8
2/8
4/8
7/8
2/8
3/8
Next fit
1
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit
1
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Next fit
1
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
where n is the number of items
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
and s be the number of non-empty bins (using Next fit)
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i)
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i) I
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i) I
the sum of the
item weights
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i) I Opt
the sum of the
item weights
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i) I Opt
the sum of the
item weights
the optimal number of bins
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i) I Opt
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i) I Opt
therefore s 2 · Opt
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i) I Opt
therefore s 2 · Opt in other words the Next Fit is never worse than twice the optimal
Next fit
1
4/8
2/8
4/8
7/8
2/8
3/8
Next fit runs in O(n) time but how good is it?
Let fill(i) be the sum of item sizes in bin i
Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s)
and s be the number of non-empty bins (using Next fit)
so s/2 <
1 2i s
fill(2i − 1) + fill(2i) I Opt
therefore s 2 · Opt
Approximation Algorithms
An algorithm A is an α-approximation algorithm for problem P if,
◦ A runs in polynomial time
◦ A always outputs a solution with value s
within an α factor of Opt
Approximation Algorithms
An algorithm A is an α-approximation algorithm for problem P if,
◦ A runs in polynomial time
◦ A always outputs a solution with value s
Here P is an optimisation problem with optimal solution of value Opt
within an α factor of Opt
Approximation Algorithms
An algorithm A is an α-approximation algorithm for problem P if,
◦ A runs in polynomial time
◦ A always outputs a solution with value s
Here P is an optimisation problem with optimal solution of value Opt
• If P is a maximisation problem,
Opt
α s Opt
within an α factor of Opt
Approximation Algorithms
An algorithm A is an α-approximation algorithm for problem P if,
◦ A runs in polynomial time
◦ A always outputs a solution with value s
Here P is an optimisation problem with optimal solution of value Opt
• If P is a maximisation problem,
Opt
α s Opt
within an α factor of Opt
• If P is a minimisation problem (like BINPACKING), Opt s α · Opt
Approximation Algorithms
An algorithm A is an α-approximation algorithm for problem P if,
◦ A runs in polynomial time
◦ A always outputs a solution with value s
Here P is an optimisation problem with optimal solution of value Opt
• If P is a maximisation problem,
Opt
α s Opt
within an α factor of Opt
• If P is a minimisation problem (like BINPACKING), Opt s α · Opt
We have seen a 2-approximation algorithm for BINPACKING
Approximation Algorithms
An algorithm A is an α-approximation algorithm for problem P if,
◦ A runs in polynomial time
◦ A always outputs a solution with value s
Here P is an optimisation problem with optimal solution of value Opt
• If P is a maximisation problem,
Opt
α s Opt
within an α factor of Opt
• If P is a minimisation problem (like BINPACKING), Opt s α · Opt
We have seen a 2-approximation algorithm for BINPACKING
the number of bins used, s is always between Opt and 2 · Opt
Approximation Algorithms
An algorithm A is an α-approximation algorithm for problem P if,
◦ A runs in polynomial time
◦ A always outputs a solution with value s
Here P is an optimisation problem with optimal solution of value Opt
• If P is a maximisation problem,
Opt
α s Opt
within an α factor of Opt
• If P is a minimisation problem (like BINPACKING), Opt s α · Opt
We have seen a 2-approximation algorithm for BINPACKING
the number of bins used, s is always between Opt and 2 · Opt
In the examples we consider, α will be a constant but it could depend on n (the input size)
1
4/8
2/8
4/8
7/8
2/8
3/8
We have seen that Next fit is a 2-approximation algorithm for Bin packing
which runs in O(n) time
can we do better?
First fit decreasing (FFD)
1
1
4/8 4/8
7/8
3/82/82/8
First fit decreasing (FFD)
1
1
Step 1: Sort the items into non-increasing order
4/8 4/8
7/8
3/82/82/8
First fit decreasing (FFD)
1
1
4/8 4/8
7/8
3/8 2/8 2/8
Step 1: Sort the items into non-increasing order
First fit decreasing (FFD)
1
1
4/8 4/8
7/8
3/8 2/8 2/8
Step 2: Put each item in the first (left-most) bin it fits in
First fit decreasing (FFD)
1
1
4/8 4/8 3/8 2/8 2/8
Step 2: Put each item in the first (left-most) bin it fits in
7/8
First fit decreasing (FFD)
1
1
4/8 3/8 2/8 2/8
Step 2: Put each item in the first (left-most) bin it fits in
7/8
4/8
First fit decreasing (FFD)
1
1
3/8 2/8 2/8
Step 2: Put each item in the first (left-most) bin it fits in
7/8
4/8
4/8
First fit decreasing (FFD)
1
1
2/8 2/8
Step 2: Put each item in the first (left-most) bin it fits in
7/8
4/8
4/8
3/8
First fit decreasing (FFD)
1
1
2/8
Step 2: Put each item in the first (left-most) bin it fits in
7/8
4/8
4/8
3/8
2/8
First fit decreasing (FFD)
1
1
Step 2: Put each item in the first (left-most) bin it fits in
7/8
4/8
4/8
3/8
2/8
2/8
First fit decreasing (FFD)
1
1
Step 2: Put each item in the first (left-most) bin it fits in
7/8
4/8
4/8
3/8
2/8
2/8
this will be important
for the proof
First fit decreasing (FFD)
1
1
Step 2: Put each item in the first (left-most) bin it fits in
7/8
4/8
4/8
3/8
2/8
2/8
First fit decreasing (FFD)
1
1
7/8
4/8
4/8
3/8
2/8
2/8
First fit decreasing (FFD)
1
1
7/8
4/8
4/8
3/8
2/8
2/8
FFD runs in O(n2) time but how good is it?
First fit decreasing (FFD)
1
7/8
4/8
4/8
3/8
2/8
2/8
FFD runs in O(n2) time but how good is it?
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
Every bin j j contains an item of size > 1/2
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
Every bin j j contains an item of size > 1/2
because we packed big things first and each thing was
packed in the lowest numbered bin
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
Every bin j j contains an item of size > 1/2
because we packed big things first and each thing was
packed in the lowest numbered bin
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
Every bin j j contains an item of size > 1/2
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
Every bin j j contains an item of size > 1/2
each of these items has to be in a different bin (even in Opt)
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
Every bin j j contains an item of size > 1/2
each of these items has to be in a different bin (even in Opt)
So Opt uses at least 2s
3 bins
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 1: Bin j contains an item of size > 1/2
Every bin j j contains an item of size > 1/2
each of these items has to be in a different bin (even in Opt)
So Opt uses at least 2s
3 bins
or. . . s
3Opt
2
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
when FFD packed the first item into bin j,
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
when FFD packed the first item into bin j,
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
when FFD packed the first item into bin j,
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
when FFD packed the first item into bin j,
j
1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
when FFD packed the first item into bin j,
j
1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty
ss
2. and all unpacked items had size 1/2
(because we pack in non-increasing order)
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
when FFD packed the first item into bin j,
j
1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty
ss
2. and all unpacked items had size 1/2
(because we pack in non-increasing order)
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
when FFD packed the first item into bin j,
j
1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty
ss
2. and all unpacked items had size 1/2
(because we pack in non-increasing order)
2+ 2+ 2+ 2+
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
when FFD packed the first item into bin j,
j
1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty
ss
2. and all unpacked items had size 1/2
(because we pack in non-increasing order)
2+ 2+ 2+ 2+
(we only use a new bin when the item won’t fit in any previous bin)
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
when FFD packed the first item into bin j,
j
1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty
ss
2. and all unpacked items had size 1/2
(because we pack in non-increasing order)
2+ 2+ 2+ 2+
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
when FFD packed the first item into bin j,
j
1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty
ss
2. and all unpacked items had size 1/2
(because we pack in non-increasing order)
2+ 2+ 2+ 2+
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
when FFD packed the first item into bin j,
j
1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty
ss
2. and all unpacked items had size 1/2
(because we pack in non-increasing order)
2+ 2+ 2+ 2+ 1+
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
j
ss
2+ 2+ 2+ 2+ 1+
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
j
ss
2+ 2+ 2+ 2+ 1+
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
j
ss
2+ 2+ 2+ 2+ 1+
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
j
ss
2+ 2+ 2+ 2+ 1+
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
otherwise we would have packed them there
j
ss
2+ 2+ 2+ 2+ 1+
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
j
ss
2+ 2+ 2+ 2+ 1+
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
so I > min{j − 1, 2(s − j) + 1}
j
ss
2+ 2+ 2+ 2+ 1+
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
so I > min{j − 1, 2(s − j) + 1}
recall I is the total weight of all items
j
ss
2+ 2+ 2+ 2+ 1+
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
so I > min{j − 1, 2(s − j) + 1}
recall I is the total weight of all items
pairing these with these
considerconsider
j
ss
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
so I > min{j − 1, 2(s − j) + 1}
recall I is the total weight of all items
pairing these with these
considerconsider
j
ss
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
this + this
> 1
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
so I > min{j − 1, 2(s − j) + 1}
recall I is the total weight of all items
j
ss
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
so I > min{j − 1, 2(s − j) + 1}
j
ss
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
so I > min{j − 1, 2(s − j) + 1} 2s/3 − 1
j
ss
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1)
so I > min{j − 1, 2(s − j) + 1} 2s/3 − 1
by plugging in j = 2s/3
j
ss
so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items
and bin s contains at least one item
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
As 2s/3 − 1 < I
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
As 2s/3 − 1 < I and I Opt
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
As 2s/3 − 1 < I
we have that 2s/3 − 1 < Opt
and I Opt
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
As 2s/3 − 1 < I
we have that 2s/3 − 1 < Opt
and I Opt
. . . but both sides are integers. . .
so 2s/3 Opt
finally . . . 2s/3 2s/3 Opt
or s (3/2)Opt
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
Case 2: Bin j contains only items of size 1/2
Case 1: Bin j contains an item of size > 1/2
in both cases. . . s
3Opt
2
j
ss
First fit decreasing (FFD)
Consider bin j = 2s
3 (s is the number of bins FFD uses on this input)
So FFD is a 3/2-approximation algorithm for BINPACKING
Case 2: Bin j contains only items of size 1/2
Case 1: Bin j contains an item of size > 1/2
in both cases. . . s
3Opt
2
j
ss
Approximation Algorithms Summary
An algorithm A is an α-approximation algorithm for problem P if,
◦ A runs in polynomial time
◦ A always outputs a solution with value s
Here P is an optimisation problem with optimal solution of value Opt
If P is a maximisation problem,
Opt
α s Opt
within an α factor of Opt
If P is a minimisation problem (like BINPACKING), Opt s α · Opt
We have seen Next Fit which is a 2-approximation algorithm for BINPACKING
which runs in O(n) time
and First Fit Decreasing which is a 3/2-approximation algorithm for BINPACKING
which runs in O(n2) time
Bin Packing is NP-hard so solving it exactly in polynomial time would prove that P = NP

Contenu connexe

Plus de Benjamin Sach

Orthogonal Range Searching
Orthogonal Range SearchingOrthogonal Range Searching
Orthogonal Range SearchingBenjamin Sach
 
Pattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatchesPattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatchesBenjamin Sach
 
Pattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming DistancePattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming DistanceBenjamin Sach
 
Lowest Common Ancestor
Lowest Common AncestorLowest Common Ancestor
Lowest Common AncestorBenjamin Sach
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum QueriesBenjamin Sach
 
Pattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix ArraysPattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix ArraysBenjamin Sach
 
Pattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesPattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesBenjamin Sach
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingBenjamin Sach
 
Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)Benjamin Sach
 
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's AlgorithmShortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's AlgorithmBenjamin Sach
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First SearchBenjamin Sach
 
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairsShortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairsBenjamin Sach
 
Self-balancing Trees and Skip Lists
Self-balancing Trees and Skip ListsSelf-balancing Trees and Skip Lists
Self-balancing Trees and Skip ListsBenjamin Sach
 

Plus de Benjamin Sach (15)

Orthogonal Range Searching
Orthogonal Range SearchingOrthogonal Range Searching
Orthogonal Range Searching
 
Pattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatchesPattern Matching Part Two: k-mismatches
Pattern Matching Part Two: k-mismatches
 
Pattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming DistancePattern Matching Part Three: Hamming Distance
Pattern Matching Part Three: Hamming Distance
 
Lowest Common Ancestor
Lowest Common AncestorLowest Common Ancestor
Lowest Common Ancestor
 
Range Minimum Queries
Range Minimum QueriesRange Minimum Queries
Range Minimum Queries
 
Pattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix ArraysPattern Matching Part Two: Suffix Arrays
Pattern Matching Part Two: Suffix Arrays
 
Pattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesPattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix Trees
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo Hashing
 
Bloom Filters
Bloom FiltersBloom Filters
Bloom Filters
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)Minimum Spanning Trees (via Disjoint Sets)
Minimum Spanning Trees (via Disjoint Sets)
 
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's AlgorithmShortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
Shortest Paths Part 1: Priority Queues and Dijkstra's Algorithm
 
Depth First Search and Breadth First Search
Depth First Search and Breadth First SearchDepth First Search and Breadth First Search
Depth First Search and Breadth First Search
 
Shortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairsShortest Paths Part 2: Negative Weights and All-pairs
Shortest Paths Part 2: Negative Weights and All-pairs
 
Self-balancing Trees and Skip Lists
Self-balancing Trees and Skip ListsSelf-balancing Trees and Skip Lists
Self-balancing Trees and Skip Lists
 

Dernier

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Dernier (20)

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

Approximation Algorithms Part One: Constant factor approximations

  • 1. Advanced Algorithms – COMS31900 Approximation algorithms part one Constant factor approximations Benjamin Sach
  • 2. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A (this second part is the definition of NP-hard)
  • 3. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A (this second part is the definition of NP-hard) ‘yes/no’ problems
  • 4. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A (this second part is the definition of NP-hard)
  • 5. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A (this second part is the definition of NP-hard) we can solve B using A
  • 6. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A (this second part is the definition of NP-hard)
  • 7. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A If we could solve A quickly we could solve every problem in NP quickly (this second part is the definition of NP-hard)
  • 8. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A If we could solve A quickly we could solve every problem in NP quickly They are the ‘hardest’ problems in NP (this second part is the definition of NP-hard)
  • 9. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A If we could solve A quickly we could solve every problem in NP quickly They are the ‘hardest’ problems in NP (this second part is the definition of NP-hard) that you can’t solve them in polynomial time (i.e. that P = NP) Most computer scientists (I’ve met) believe
  • 10. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A If we could solve A quickly we could solve every problem in NP quickly They are the ‘hardest’ problems in NP (this second part is the definition of NP-hard) A polynomial time algorithm for an NP-complete problem is worth (a lot more than) a million dollars
  • 11. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A If we could solve A quickly we could solve every problem in NP quickly They are the ‘hardest’ problems in NP (this second part is the definition of NP-hard)
  • 12. NP-completeness recap A problem A is NP-complete if NP is the class of decision problems we can check the answer to in polynomial time A is in NP Every B in NP has a polynomial time reduction to A If we could solve A quickly we could solve every problem in NP quickly They are the ‘hardest’ problems in NP So if a problem is NP-complete, we give up right? (this second part is the definition of NP-hard)
  • 17. Bin packing Bins 1 Items 1 4/8 4/8 7/8 3/82/82/8 0 < |Item| 1 I is the sum of all item sizes
  • 18. Bin packing Bins 1 Items 1 4/8 4/8 7/8 3/82/82/8 0 < |Item| 1 |Bin| = 1 and there is an unlimited number of bins. . . I is the sum of all item sizes
  • 19. Bin packing 1 1 4/8 4/8 7/8 3/82/82/8 Problem pack all items into the fewest possible bins
  • 20. Bin packing 1 1 4/8 4/8 7/8 3/82/82/8 Problem pack all items into the fewest possible bins This is an example of an optimisation problem
  • 21. Bin packing 1 1 Problem pack all items into the fewest possible bins 4/8 4/8 7/8 2/82/8 3/8 This is an example of an optimisation problem
  • 22. Bin packing 1 1 4/8 4/8 7/8 3/82/82/8 Problem pack all items into the fewest possible bins This is an example of an optimisation problem
  • 23. Bin packing 1 1 Problem pack all items into the fewest possible bins 4/8 4/8 7/8 2/8 2/8 3/8 This is an example of an optimisation problem
  • 24. Bin packing 1 1 Problem pack all items into the fewest possible bins 4/8 4/8 7/8 2/8 2/8 3/8
  • 25. Bin packing 1 1 Problem pack all items into the fewest possible bins 4/8 4/8 7/8 2/8 2/8 3/8 The BINPACKING problem is known to be NP-hard
  • 26. Bin packing 1 1 Problem pack all items into the fewest possible bins 4/8 4/8 7/8 2/8 2/8 3/8 The BINPACKING problem is known to be NP-hard and the decision version. . . “Can you pack the items into at most k bins?” is NP-complete
  • 27. Bin packing 1 1 Problem pack all items into the fewest possible bins 4/8 4/8 7/8 2/8 2/8 3/8 The BINPACKING problem is known to be NP-hard and the decision version. . . “Can you pack the items into at most k bins?” is NP-complete In the decision version, k is part of the input
  • 28. Bin packing 1 1 Problem pack all items into the fewest possible bins 4/8 4/8 7/8 2/8 2/8 3/8 The BINPACKING problem is known to be NP-hard
  • 29. Bin packing 1 1 Problem pack all items into the fewest possible bins 4/8 4/8 7/8 2/8 2/8 3/8 The BINPACKING problem is known to be NP-hard but fortunately we can approximate
  • 30. Next fit 1 1 4/8 4/8 7/8 3/82/82/8 If item i fits into bin j: pack it, i++; else j++;
  • 31. Next fit 1 1 4/8 4/8 7/8 3/82/82/8 If item i fits into bin j: pack it, i++; else j++;
  • 32. Next fit 1 1 4/8 7/8 3/82/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8
  • 33. Next fit 1 1 4/8 7/8 3/82/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8
  • 34. Next fit 1 1 4/8 7/8 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8
  • 35. Next fit 1 1 4/8 7/8 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8
  • 36. Next fit 1 1 4/8 7/8 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8
  • 37. Next fit 1 1 7/8 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8
  • 38. Next fit 1 1 7/8 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8
  • 39. Next fit 1 1 7/8 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8
  • 40. Next fit 1 1 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8 7/8
  • 41. Next fit 1 1 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8 7/8
  • 42. Next fit 1 1 3/82/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8 7/8
  • 43. Next fit 1 1 3/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8 7/8 2/8
  • 44. Next fit 1 1 3/8 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8 7/8 2/8
  • 45. Next fit 1 1 If item i fits into bin j: pack it, i++; else j++; 4/8 2/8 4/8 7/8 2/8 3/8
  • 47. Next fit 1 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it?
  • 48. Next fit 1 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? where n is the number of items
  • 49. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it?
  • 50. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i and s be the number of non-empty bins (using Next fit)
  • 51. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit)
  • 52. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i)
  • 53. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i) I
  • 54. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i) I the sum of the item weights
  • 55. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i) I Opt the sum of the item weights
  • 56. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i) I Opt the sum of the item weights the optimal number of bins
  • 57. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i) I Opt
  • 58. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i) I Opt therefore s 2 · Opt
  • 59. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i) I Opt therefore s 2 · Opt in other words the Next Fit is never worse than twice the optimal
  • 60. Next fit 1 4/8 2/8 4/8 7/8 2/8 3/8 Next fit runs in O(n) time but how good is it? Let fill(i) be the sum of item sizes in bin i Observe that fill(2i − 1) + fill(2i) > 1 (for 1 2i s) and s be the number of non-empty bins (using Next fit) so s/2 < 1 2i s fill(2i − 1) + fill(2i) I Opt therefore s 2 · Opt
  • 61. Approximation Algorithms An algorithm A is an α-approximation algorithm for problem P if, ◦ A runs in polynomial time ◦ A always outputs a solution with value s within an α factor of Opt
  • 62. Approximation Algorithms An algorithm A is an α-approximation algorithm for problem P if, ◦ A runs in polynomial time ◦ A always outputs a solution with value s Here P is an optimisation problem with optimal solution of value Opt within an α factor of Opt
  • 63. Approximation Algorithms An algorithm A is an α-approximation algorithm for problem P if, ◦ A runs in polynomial time ◦ A always outputs a solution with value s Here P is an optimisation problem with optimal solution of value Opt • If P is a maximisation problem, Opt α s Opt within an α factor of Opt
  • 64. Approximation Algorithms An algorithm A is an α-approximation algorithm for problem P if, ◦ A runs in polynomial time ◦ A always outputs a solution with value s Here P is an optimisation problem with optimal solution of value Opt • If P is a maximisation problem, Opt α s Opt within an α factor of Opt • If P is a minimisation problem (like BINPACKING), Opt s α · Opt
  • 65. Approximation Algorithms An algorithm A is an α-approximation algorithm for problem P if, ◦ A runs in polynomial time ◦ A always outputs a solution with value s Here P is an optimisation problem with optimal solution of value Opt • If P is a maximisation problem, Opt α s Opt within an α factor of Opt • If P is a minimisation problem (like BINPACKING), Opt s α · Opt We have seen a 2-approximation algorithm for BINPACKING
  • 66. Approximation Algorithms An algorithm A is an α-approximation algorithm for problem P if, ◦ A runs in polynomial time ◦ A always outputs a solution with value s Here P is an optimisation problem with optimal solution of value Opt • If P is a maximisation problem, Opt α s Opt within an α factor of Opt • If P is a minimisation problem (like BINPACKING), Opt s α · Opt We have seen a 2-approximation algorithm for BINPACKING the number of bins used, s is always between Opt and 2 · Opt
  • 67. Approximation Algorithms An algorithm A is an α-approximation algorithm for problem P if, ◦ A runs in polynomial time ◦ A always outputs a solution with value s Here P is an optimisation problem with optimal solution of value Opt • If P is a maximisation problem, Opt α s Opt within an α factor of Opt • If P is a minimisation problem (like BINPACKING), Opt s α · Opt We have seen a 2-approximation algorithm for BINPACKING the number of bins used, s is always between Opt and 2 · Opt In the examples we consider, α will be a constant but it could depend on n (the input size)
  • 68. 1 4/8 2/8 4/8 7/8 2/8 3/8 We have seen that Next fit is a 2-approximation algorithm for Bin packing which runs in O(n) time can we do better?
  • 69. First fit decreasing (FFD) 1 1 4/8 4/8 7/8 3/82/82/8
  • 70. First fit decreasing (FFD) 1 1 Step 1: Sort the items into non-increasing order 4/8 4/8 7/8 3/82/82/8
  • 71. First fit decreasing (FFD) 1 1 4/8 4/8 7/8 3/8 2/8 2/8 Step 1: Sort the items into non-increasing order
  • 72. First fit decreasing (FFD) 1 1 4/8 4/8 7/8 3/8 2/8 2/8 Step 2: Put each item in the first (left-most) bin it fits in
  • 73. First fit decreasing (FFD) 1 1 4/8 4/8 3/8 2/8 2/8 Step 2: Put each item in the first (left-most) bin it fits in 7/8
  • 74. First fit decreasing (FFD) 1 1 4/8 3/8 2/8 2/8 Step 2: Put each item in the first (left-most) bin it fits in 7/8 4/8
  • 75. First fit decreasing (FFD) 1 1 3/8 2/8 2/8 Step 2: Put each item in the first (left-most) bin it fits in 7/8 4/8 4/8
  • 76. First fit decreasing (FFD) 1 1 2/8 2/8 Step 2: Put each item in the first (left-most) bin it fits in 7/8 4/8 4/8 3/8
  • 77. First fit decreasing (FFD) 1 1 2/8 Step 2: Put each item in the first (left-most) bin it fits in 7/8 4/8 4/8 3/8 2/8
  • 78. First fit decreasing (FFD) 1 1 Step 2: Put each item in the first (left-most) bin it fits in 7/8 4/8 4/8 3/8 2/8 2/8
  • 79. First fit decreasing (FFD) 1 1 Step 2: Put each item in the first (left-most) bin it fits in 7/8 4/8 4/8 3/8 2/8 2/8 this will be important for the proof
  • 80. First fit decreasing (FFD) 1 1 Step 2: Put each item in the first (left-most) bin it fits in 7/8 4/8 4/8 3/8 2/8 2/8
  • 81. First fit decreasing (FFD) 1 1 7/8 4/8 4/8 3/8 2/8 2/8
  • 82. First fit decreasing (FFD) 1 1 7/8 4/8 4/8 3/8 2/8 2/8 FFD runs in O(n2) time but how good is it?
  • 83. First fit decreasing (FFD) 1 7/8 4/8 4/8 3/8 2/8 2/8 FFD runs in O(n2) time but how good is it?
  • 84. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) ss
  • 85. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) j ss
  • 86. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) j ss
  • 87. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 j ss
  • 88. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 j ss
  • 89. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 Every bin j j contains an item of size > 1/2 j ss
  • 90. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 Every bin j j contains an item of size > 1/2 because we packed big things first and each thing was packed in the lowest numbered bin j ss
  • 91. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 Every bin j j contains an item of size > 1/2 because we packed big things first and each thing was packed in the lowest numbered bin j ss
  • 92. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 Every bin j j contains an item of size > 1/2 j ss
  • 93. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 Every bin j j contains an item of size > 1/2 each of these items has to be in a different bin (even in Opt) j ss
  • 94. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 Every bin j j contains an item of size > 1/2 each of these items has to be in a different bin (even in Opt) So Opt uses at least 2s 3 bins j ss
  • 95. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 1: Bin j contains an item of size > 1/2 Every bin j j contains an item of size > 1/2 each of these items has to be in a different bin (even in Opt) So Opt uses at least 2s 3 bins or. . . s 3Opt 2 j ss
  • 96. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 j ss
  • 97. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 when FFD packed the first item into bin j, j ss
  • 98. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 when FFD packed the first item into bin j, j ss
  • 99. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 when FFD packed the first item into bin j, j ss
  • 100. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 when FFD packed the first item into bin j, j 1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty ss
  • 101. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 when FFD packed the first item into bin j, j 1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty ss 2. and all unpacked items had size 1/2 (because we pack in non-increasing order)
  • 102. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items when FFD packed the first item into bin j, j 1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty ss 2. and all unpacked items had size 1/2 (because we pack in non-increasing order)
  • 103. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items when FFD packed the first item into bin j, j 1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty ss 2. and all unpacked items had size 1/2 (because we pack in non-increasing order) 2+ 2+ 2+ 2+
  • 104. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items when FFD packed the first item into bin j, j 1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty ss 2. and all unpacked items had size 1/2 (because we pack in non-increasing order) 2+ 2+ 2+ 2+ (we only use a new bin when the item won’t fit in any previous bin)
  • 105. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items when FFD packed the first item into bin j, j 1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty ss 2. and all unpacked items had size 1/2 (because we pack in non-increasing order) 2+ 2+ 2+ 2+
  • 106. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item when FFD packed the first item into bin j, j 1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty ss 2. and all unpacked items had size 1/2 (because we pack in non-increasing order) 2+ 2+ 2+ 2+
  • 107. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item when FFD packed the first item into bin j, j 1. all bins j, (j + 1), . . . , (s − 2), (s − 1) were empty ss 2. and all unpacked items had size 1/2 (because we pack in non-increasing order) 2+ 2+ 2+ 2+ 1+
  • 108. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item j ss 2+ 2+ 2+ 2+ 1+
  • 109. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 j ss 2+ 2+ 2+ 2+ 1+
  • 110. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 j ss 2+ 2+ 2+ 2+ 1+ so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 111. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) j ss 2+ 2+ 2+ 2+ 1+ so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 112. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) otherwise we would have packed them there j ss 2+ 2+ 2+ 2+ 1+ so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 113. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) j ss 2+ 2+ 2+ 2+ 1+ so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 114. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) so I > min{j − 1, 2(s − j) + 1} j ss 2+ 2+ 2+ 2+ 1+ so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 115. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) so I > min{j − 1, 2(s − j) + 1} recall I is the total weight of all items j ss 2+ 2+ 2+ 2+ 1+ so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 116. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) so I > min{j − 1, 2(s − j) + 1} recall I is the total weight of all items pairing these with these considerconsider j ss so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 117. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) so I > min{j − 1, 2(s − j) + 1} recall I is the total weight of all items pairing these with these considerconsider j ss so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item this + this > 1
  • 118. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) so I > min{j − 1, 2(s − j) + 1} recall I is the total weight of all items j ss so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 119. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) so I > min{j − 1, 2(s − j) + 1} j ss so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 120. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) so I > min{j − 1, 2(s − j) + 1} 2s/3 − 1 j ss so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 121. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 This gives a total of 2(s − j) + 1 items, none of which fits into bins 1, 2, 3, . . . , (j − 1) so I > min{j − 1, 2(s − j) + 1} 2s/3 − 1 by plugging in j = 2s/3 j ss so Bins j, (j + 1), . . . , (s − 2), (s − 1) each contain at least two items and bin s contains at least one item
  • 122. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 As 2s/3 − 1 < I j ss
  • 123. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 As 2s/3 − 1 < I and I Opt j ss
  • 124. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 As 2s/3 − 1 < I we have that 2s/3 − 1 < Opt and I Opt j ss
  • 125. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 As 2s/3 − 1 < I we have that 2s/3 − 1 < Opt and I Opt . . . but both sides are integers. . . so 2s/3 Opt finally . . . 2s/3 2s/3 Opt or s (3/2)Opt j ss
  • 126. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) j ss
  • 127. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) Case 2: Bin j contains only items of size 1/2 Case 1: Bin j contains an item of size > 1/2 in both cases. . . s 3Opt 2 j ss
  • 128. First fit decreasing (FFD) Consider bin j = 2s 3 (s is the number of bins FFD uses on this input) So FFD is a 3/2-approximation algorithm for BINPACKING Case 2: Bin j contains only items of size 1/2 Case 1: Bin j contains an item of size > 1/2 in both cases. . . s 3Opt 2 j ss
  • 129. Approximation Algorithms Summary An algorithm A is an α-approximation algorithm for problem P if, ◦ A runs in polynomial time ◦ A always outputs a solution with value s Here P is an optimisation problem with optimal solution of value Opt If P is a maximisation problem, Opt α s Opt within an α factor of Opt If P is a minimisation problem (like BINPACKING), Opt s α · Opt We have seen Next Fit which is a 2-approximation algorithm for BINPACKING which runs in O(n) time and First Fit Decreasing which is a 3/2-approximation algorithm for BINPACKING which runs in O(n2) time Bin Packing is NP-hard so solving it exactly in polynomial time would prove that P = NP