Next-fit Bin Packing
   HOME

TheInfoList



OR:

Next-fit is an
online algorithm In computer science, an online algorithm is one that can process its input piece-by-piece in a serial fashion, i.e., in the order that the input is fed to the algorithm, without having the entire input available from the start. In contrast, an o ...
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 A heuristic (; ), or heuristic technique, is any approach to problem solving or self-discovery that employs a practical method that is not guaranteed to be optimal, perfect, or rational, but is nevertheless sufficient for reaching an immediate ...
: * It keeps a ''current bin'', which is initially empty. * When an item arrives, it checks whether the item fits into the current bin. ** If it fits, it is placed inside it. ** Otherwise, the current bin is closed, a new bin is opened and the coming item is placed inside this new bin. 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 David Stifler Johnson (December 9, 1945 – March 8, 2016) was an American computer scientist specializing in algorithms and optimization. He was the head of the Algorithms and Optimization Department of AT&T Labs Research from 1988 to 2013, an ...
in his doctoral thesis in 1973.


Run time

The running time of NextFit can be bounded by \mathcal(n), where n is the number of items in the list.


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 L, NF(L) \leq 2 \cdot \mathrm(L) -1 . The intuition to the proof s the following. The number of bins used by this algorithm is no more than twice the optimal number of bins. In other words, it is impossible for 2 bins to be at most half full because such a possibility implies that at some point, exactly one bin was at most half full and a new one was opened to accommodate an item of size at most B/2. But since the first one has at least a space of B/2, the algorithm will not open a new bin for any item whose size is at most B/2. Only after the bin fills with more than B/2 or if an item with a size larger than B/2 arrives, the algorithm may open a new bin. Thus if we have K bins, at least K-1 bins are more than half full. Therefore, \sum_ s(i)>\tfracB. Because \tfrac is a lower bound of the optimum value \mathrm, we get that K-1<2\mathrm and therefore K \leq 2\mathrm.


Lower bound

For each N \in \mathbb, there exists a list L such that \mathrm(L) = N and NF(L) = 2 \cdot \mathrm(L) -2. The family of lists for which it holds that NF(L) = 2 \cdot \mathrm(L) - 2 is given by L := \left(\frac,\frac,\frac,\frac, \dots, \frac,\frac\right) with , L, = 4(N-1). The optimal solution for this list has N - 1 bins containing two items with size 1/2 and one bin with 2(N-1) items with size 1/2(N-1) (i.e., N bins total), while the solution generated by NF has 2(N-1) bins with one item of size 1/2 and one item with size 1/(2(N-1)).


Bounded item size

If the maximum size of an item is \alpha, then the asymptotic approximation ratio ratio R_^\infty satisfies: * R_^\infty(\text\leq\alpha) \leq 2 for all \alpha \geq 1/2; * R_^\infty(\text\leq\alpha) \leq 1/(1-\alpha) for all \alpha \leq 1/2.


Other properties

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


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 k bins open and chooses the first bin in which the item fits. For k\geq 2, NkF delivers results that are improved compared to the results of NF, however, increasing k to constant values larger than 2 improves the algorithm no further in its worst-case behavior. If algorithm A is an AlmostAnyFit-algorithm and m = \lfloor 1/\alpha\rfloor \geq 2 then R_^(\text\leq\alpha)\leq R_^(\text{size}\leq\alpha) = 1+1/m.


See also

* Next-fit-decreasing (NFD) is the
offline In computer technology and telecommunications, online indicates a state of connectivity and offline indicates a disconnected state. In modern terminology, this usually refers to an Internet connection, but (especially when expressed "on line" or ...
variant of Next-Fit: it accepts all input items, orders them by descending size, and calls Next-Fit. Its asymptotic approximation ratio is much better: less than 1.7, instead of 2.


References

Bin packing