0% found this document useful (0 votes)
214 views8 pages

CSC 301 - Design and Analysis of Algorithms

This document discusses approximation algorithms for bin packing problems. It introduces bin packing, where items of various sizes must be packed into bins of unit capacity using the fewest number of bins. It then describes three approximation algorithms - Next Fit, First Fit, and Best Fit - that provide solutions within a factor of the optimal solution in polynomial time. Next Fit uses at most 11/9 times the optimal number of bins, while First Fit uses at most the optimal number of bins. Best Fit can run in linear time using a balanced binary tree. The document also discusses offline algorithms that sort items by decreasing size before applying heuristics like First Fit Decreasing or Best Fit Decreasing.

Uploaded by

Fabiha Anjum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
214 views8 pages

CSC 301 - Design and Analysis of Algorithms

This document discusses approximation algorithms for bin packing problems. It introduces bin packing, where items of various sizes must be packed into bins of unit capacity using the fewest number of bins. It then describes three approximation algorithms - Next Fit, First Fit, and Best Fit - that provide solutions within a factor of the optimal solution in polynomial time. Next Fit uses at most 11/9 times the optimal number of bins, while First Fit uses at most the optimal number of bins. Best Fit can run in linear time using a balanced binary tree. The document also discusses offline algorithms that sort items by decreasing size before applying heuristics like First Fit Decreasing or Best Fit Decreasing.

Uploaded by

Fabiha Anjum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CSC 301 – Design and Analysis of Algorithms

Instructor: Dr. M. Hasan Jamal


Lecture# 08: Approximation Algorithms – Bin Packing

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.

• An algorithm is an α-approximation algorithm for an optimization problem if:


• The algorithm runs in polynomial time
• The algorithm always produces a solution that is within a factor of α of the optimal solution

• For a given problem instance ,

2
Approximation Algorithms: Bin Packing
• Given
  items with sizes such that for pack them into the fewest number of unit
capacity bins.

1 …

0.5, 0.7, 0.5, 0.2, 0.4, 0.2, 0.5, 0.1, 0.6.


Optimal packing:

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.

0.5, 0.7, 0.5, 0.2, 0.4, 0.2, 0.5, 0.1, 0.6.

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.5, 0.7, 0.5, 0.2, 0.4, 0.2, 0.5, 0.1, 0.6.

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.5, 0.7, 0.5, 0.2, 0.4, 0.2, 0.5, 0.1, 0.6.

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

You might also like