SlideShare a Scribd company logo
1 of 129
Download to read offline
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

More Related Content

More from Benjamin Sach

More from 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
 

Recently uploaded

The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
heathfieldcps1
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
Krashi Coaching
 

Recently uploaded (20)

How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptxREPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 

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