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)
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
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)
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
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