Bin Packing Problem - First-fit Algorithm

First-fit Algorithm

This is a very straightforward greedy approximation algorithm. The algorithm processes the items in arbitrary order. For each item, it attempts to place the item in the first bin that can accommodate the item. If no bin is found, it opens a new bin and puts the item within the new bin.

It is rather simple to show this algorithm achieves an approximation factor of 2. This is due to the observation that at any given time, it is impossible for 2 bins to be at most half full. The reason is that if at some point a bin was at most half full, meaning it has at least a space of V / 2, the algorithm will not open a new bin for any item whose size is at most V / 2. Only after the bin fills with more than V / 2 or if an item with a size larger than V / 2 arrives, the algorithm may open a new bin.

Thus if we have B bins, at least B − 1 bins are more than half full. Therefore . Because is a lower bound of the optimum value OPT, we get that B − 1 < 2OPT and therefore B ≤ 2OPT. See analysis below for better approximation results.

Read more about this topic:  Bin Packing Problem