CSC 301 - Design and Analysis of Algorithms
CSC 301 - Design and Analysis of Algorithms
1
Approximation Algorithms
• Many
optimization problems exist for which there is no known polynomial time
algorithm for its solution.
• Approximation algorithms allow for getting a solution close to the (optimal) solution
of an optimization problem in polynomial time.
2
Approximation Algorithms: Bin Packing
• Given
items with sizes such that for pack them into the fewest number of unit
capacity bins.
1 …
0.1
0.2
0.5
0.5
0.6 Mopt = 4 3
0.7
0.5 0.4
0.2
Approximation Algorithms: Bin Packing
• Fit Algorithm: Check to see if the current item fits in the current bin. If so, then
Next
place it there, otherwise start a new bin.
1 0.2 0.1
0.7 0.2
0.5 0.5 0.6
0.5 0.4
M=6
• Theorem: Let be the optimal number of bins required to pack a list of items. Next Fit
will use at most bins. There exist sequences such that Next Fit uses bins. 4
Approximation Algorithms: Bin Packing
• Fit Algorithm: Scans the bins in order and place the new item in the first bin that
First
is large enough to hold it. A new bin is created only when an item does not fit in the
previous bins.
0.1
0.5 0.2
1 0.2
0.7 0.6
0.5 0.4 0.5
M=5
• Theorem: Let be the optimal number of bins required to pack a list of items. First
5
Fit will never use more than bins. There exist sequences such that First Fit uses
bins.
Approximation Algorithms: Bin Packing
• Fit Algorithm: New items placed in a bin where it fits the tightest. If it does not fit
Best
in any bin, then start a new bin.
0.1
0.5 0.2
1 0.2
0.7 0.6
0.5 0.4 0.5
M=5
• Can be implemented in time, by using a balanced binary tree storing bins ordered
by remaining capacity. 6
Approximation Algorithms: Bin Packing
Major problems with all online algorithms is that it is hard to pack large items,
especially when they occur late in the input.
In offline Algorithms where we know the sizes of all items in advance, a natural
solution is to first sort items by size, from largest to smallest, and then apply the
following heuristics:
• First Fit Decreasing
• Best Fit Decreasing
0.7, 0.6, 0.5, 0.5, 0.5, 0.4, 0.2, 0.2, 0.1.
0.1
0.2 0.4 0.5
0.2
1
0.7 0.6 0.5 0.5 7
M=4
THANK YOU
8