Next-fit bin packing

Last updated

Next-fit is an online algorithm for bin packing. Its input is a list of items of different sizes. Its output is a packing - a partition of the items into bins of fixed capacity, such that the sum of sizes of items in each bin is at most the capacity. Ideally, we would like to use as few bins as possible, but minimizing the number of bins is an NP-hard problem. The next-fit algorithm uses the following heuristic:

Contents

Next-Fit is a bounded space algorithm - it requires only one partially-filled bin to be open at any time. The algorithm was studied by David S. Johnson in his doctoral thesis [1] in 1973.

Run time

The running time of NextFit can be bounded by , where is the number of items in the list. [2]

Approximation ratio

Denote by NF(L) the number of bins used by NextFit, and by OPT(L) the optimal number of bins possible for the list L.

Upper bound

Then, for each list , . For the sake of convenience, assume that each bin has a maximum capacity of . The intuition behind the proof is the following. If is the optimal number of bins, then . This follows from the fact that otherwise, at least one bin in an optimal solution would exceed the capacity, and that is an integer.

Due to the structure of the algorithm, the total size of two consecutive bins (except for the last one) exceeds . This means that if is the number of bins produced by the algorithm, then .

Combining both inequalities, we get , thus .

Lower bound

For each , there exists a list such that and .

The family of lists for which it holds that is given by with . The optimal solution for this list has bins containing two items with size and one bin with items with size (i.e., bins total), while the solution generated by NF has bins with one item of size and one item with size .

Bounded item size

If the maximum size of an item is , then the asymptotic approximation ratio ratio satisfies:

Other properties

Next-Fit packs a list and its inverse into the same number of bins. [3]

Next-k-Fit (NkF)

Next-k-Fit is a variant of Next-Fit, but instead of keeping only one bin open, the algorithm keeps the last bins open and chooses the first bin in which the item fits.

For , NkF delivers results that are improved compared to the results of NF, however, increasing to constant values larger than improves the algorithm no further in its worst-case behavior. If algorithm is an AlmostAnyFit-algorithm and then . [1]

See also

References

  1. 1 2 Johnson, David S (1973). "Near-optimal bin packing algorithms" (PDF). Massachusetts Institute of Technology.
  2. Suri, Subhash. "Bin Packing". UCSB Computer Science. Retrieved 7 October 2021.
  3. Fisher, David C. (1988-12-01). "Next-fit packs a list and its reverse into the same number of bins" . Operations Research Letters. 7 (6): 291–293. doi:10.1016/0167-6377(88)90060-0. ISSN   0167-6377.