Bin Packing Can Be Solved Within in Linear Time
Bin Packing Can Be Solved Within in Linear Time
W, F E R N A N D E Z de la V E G A
c. N. R, S., 54 Bd. Raspail
Paris 75 006, France*
and
G. S. L U E K E R * *
Dept. Info. Comp. Sci., Univ. of California
Irvine, CA 92 717 U.S.A.
Received 22 May 1981
For any list L of n numbers in (0, 1] let L* denote the minimum number of unit capacity
bins needed to pack the elements of L. We prove that, for every positive e, there exists an O(n)-time
algorithm S such that, if S(L) denotes the number of bins used by S for L, then S(L)/L*~_I+e
for any L provided L* is sufficiently large.
1. Introduction
2. Terminology
Besides the usual format of the data in a bin-packing problem which is assumed
to be presented as a list L = x l x 2 . . . x n of numbers in (0, I] (we shall represent
lists as words in the one dimensional case since we use concatenation), we shall
use also the notion of a multiset in which some elements may appear more than
once. For instance, to a list L whose elements achieve m distinct values Yl . . . . , ym,
we shall associate the multiset M z denoted as in [9]
M r = {nl" Yl . . . . , n~. ym},
with the meaning that, for each i, ni denotes the number of terms of L equal to Yi.
We shall say that n~ is the multiplicity of yl in ML.
For any list L we denote its length by IL[. We denote by V(L) the sum of
the elements of L.
Let X be a bin used in a packing. By the type of X we shall mean the multi-
set of numbers which are assigned to X. For a given packing problem, determined
by a list L whose elements take m distinct values y~<y2< ... <Ym, we can represent
m
the types by vectors in N m, the vector T = ( t l , ..., t,,) with ~ hy~<=1, representing
t=1
the type of a bin which contains, for each i, exactly h numbers equal to y~. We
shall say that the type T is saturated if we have y~+ ~ h y i > 1.
,=1
We note that to each packing of a list L there corresponds in an obvious way a
multiset of types of bins. I f ~ ' is a multiset of types of bins corresponding to a pack-
ing of L and M = M ~ . is the multiset of numbers corresponding to L, we shall say,
with a slight abuse of language, that J [ is a packing of M.
which is the number of ways one can choose m + 1 nonnegative integers which
add to k. (The first m numbers are item counts and the last one is for padding
the sum out to k.)
Let q=q(M)<=z(q, m) denote the actual number of types. Let these types
be arranged in some order and let T~=(t~ .... , t,~) denote the vector representing
the ith type. Consider the following linear integer program, to which we shall refer
as program P1.
q
Minimize ~ ai
i=1
subject to
q
(1) ~ a ~ t j i >. .n j . j. =. 1. m
i=l
and
ai -~0 i : 1, ..., q.
From a solution of this program, we can, by deflating perhaps some types, obtain
a solution (a[' ..... a~) for which the constraints (1) become equalities. Hence
converting the constraints into equalities does not change the value of the program
(it certainly can't increase it) and (a~'..... a~) defines in an obvious way an optimal
multiset of types. Now if (~1 .... , c~q) is a solution of the ordinary linear program
352 W. F E R N A N D E Z D E LA V E G A , G . S . L U E K E R
The inequality between the first and last expressions means that the multiset of
types {a~*- 7'1, ..., a~*- Tq} solves RBP (q, m) on the instance M within the addi-
tive constant* q. To find (a~*, ..., a~*) amounts essentially to solving the ordinary
linear program P2.
Since both the number of variables and the number of constraints of P2
have bounds depending only on r/ and m, this can be done in time depending only
on these parameters. II
3.2. Converting bin-packing within 1+ e into restricted bin-packing.
Let e > 0 be given and let ~ = e / ( e + 2 ) denote the root of (1 + e a ) ( 1 - ~ l ) - ~ =
= 1 +e. We set m=Fefz-J. Let L=x~ ... x, be the list to be packed and let l denote
the number of x~'s smaller than e~. We define h by n - l = m h + r , r<=m-1, and
suppose first h > 0 . Let L,=KoY~K~...ymKmR be anylist obtained by rearranging
L in such a way that:
(i) 32o contains the l terms <51,
(ii) IKII=IK21. . . . . I K m [ = h - 1,
(iii) for i = 1 , ..., m - 1 each term x in K~ satisfies yi~x<=y~+~,
(iv) each term x in KmR satisfies x>=ym.
These conditions amount exactly to saying that, if L ' is the list obtained by sorting
L in non-decreasing order, then yi is the term of rank l + ( i - 1 ) h + l in L ' and,
writing L'=YoytY~...y,,Y~, that the sub-lists Ko, K~ ..... K,,R are arbitrary
rearrangements of Y0, II1, ..., Y,, respectively. Hence to find a list L~ fulfilling
the forementioned conditions amounts essentially to finding the y~'s.
Using the fact that the "selection problem" which consists in finding the
kth largest term of a list of length l can be solved in time O(l) [1], it can be shown
that all the yi's can be found in time O(n log~ m), hence in time Cn log (I/z) where
C is an absolute constant.
We require now the following definition. For any two lists of same length
L=x~...x, and K = y , . . . y , we shall say that L d o m i n a t e s K a n d write L ~ - K or
K.<L if we have a~=>y~, i = 1 , ..., n. It is clear that L>-.K implies L*>=K*.
Consider the lists L~=Koy~...y~R and L3-- -- KoY2...y,,,
h h lhR. Clearly we
have IL2]= lL31=n and Lz..<Lt-.<L3. Since from a packing of L3 we can get imme-
diately a packing of L~ (hence a packing of L) using the same number of bins, if
we show on one hand that we can indeed obtain in linear time a packing of L3 using
no more than (I-~;1)-IL~-b-C bins and, on the other hand, that the inequality
= L z ( l + a ~ ) holds, then it follows that our packing of L uses less than
* D. J o h n s o n pointed out to us that we can replace here q by m since P2 will always have
a solution with at m o s t m n o n - z e r o e~'s.
BIN PACKING WITHIN l+e 353
Proof. Let J~ denote the set of indexes of the vectors in L for each of which the
largest component is the ith one (in case of ties, an arbitrary choice is made within
the set of indexes of the largest components of the considered vector). Let L~ denote
the list of the values of the ith component of the vectors with indexes in J~. Clearly
a packing of L i defines a generalized packing of these vectors. Now, for any flied
e, we can, using our one dimensional packing algorithm, pack L~ within 1 + e in
d
linear time. Hence we can pack L in a number of bins not greater than (1 -I-e) ~ L*
i=1
also in linear time. On the other hand the vectors with indexes in J~ do not pack
in less than L* bins and this implies
d
L* _-> max {L~ ..... L~} => d -~ ~ ' L~.
i=i
5. Concluding remarks
s a m p l i n g was used in a sorting algorithm with good expected behavior; see [12]
for a survey of algorithms with good expected behavior. [13, 15] considered the
application o f linear p r o g r a m m i n g to bin packing in a m a n n e r similar to that
employed here; [13] observes that a linear p r o g r a m m i n g solution.
We are very grateful to D a v i d J o h n s o n for b r i n g i n g some of the earlier
research to our a t t e n t i o n , a n d for also m a k i n g other helpful r e m a r k s on a n early
manuscript.
References
[1] M. BLUM,R. W. Ft.OVD, V. PRATT, R. L. RIVESTand R. E. TARJAN, Time bounds for selec-
tion, J. Comput. Sys. Sci., 7 (1973), 4 4 8 4 6 1 .
[2] M. R. GAREY, R. L. GRAHAM,D. S. JOHNSON and A. C. YAO, Multiprocessor scheduling
as generalized bin-packing, J. Combinatorial Theory A 21 (1976), 257--298.
[3] M. R. GAREY and D. S. JOHNSON, Computers and Intractability, Freeman, San Francisco,
1979.
[4] M. R. GAREYand D. S. JOHNSON, Approximation algorithms for bin packing problems: a
survey, preprint 1980.
[5] D. S. JOHNSON,.Near optimal bh7 packing algorithms, Ph.D. Th., HIT, Cambridge, Mass., June
1973.
[6] D. S. JOHNSON, Fast algorithms for bin packing, J. Comptr. Syst. Sci. 8 (1974), 272--314.
[7] D. S. JOHNSON, A. DEMERS, J. D. UI-LMAN,M. R. GAREY and R. L. GRAHAM, Worst case
bounds for simple one-dimensional packing algorithms, SIAM J. Comptg. 3 (1974), 299--
325.
[8] R. M. KARl:', Reducibility among combinatorial problems, in: Complexity of Computer calcula-
tions. (R+ E+ MilIer and J. W. Thatcher, Eds.) Plenum Press, New York, 1972, 85--103.
[9] D. E. KNUTH, The Art of Computer Progratnmb~g, Vol. 3, Sorting and Searching, Addison-
Wesley, Reading, Mass., I973.
[10] A. SCHONHAQE,M. S. PATERSONand N. PIPPENGER, Finding the median, J. Cornput. Sys.
Sci. 13 (1976), 184--199.
[11] A. C. Yao, New algorithms for bin packing. J. A C M 27, 2 (Apr. 1980).
[12] J. L. BENTLEY, Probabilistic analysis of algorithms, Applied Probabilit)~Computer Science,
the hTterface, Boca Raton, Florida, January 1981.
[13] P. C. GILMORE and R. E. Go~,tORY, A linear programming approach to the cutting-stock
problem, Operations Research 9 (1961), 849--859.
[14] O. H. IBARRAand C. E. KIM, Fast approximation aleorithms for the knapsack and sum of
subset problems, Journal of the A C M 22 (1975), 463--468.
[15] L. V. KANTOROWCH,Mathematical methods of organizing and planning production, Manage-
ment Science 6, 4 (July 1960), 366--422.
[16] S. SAHNI, General techniques for combinatorial approximation, Operatiotls Research 25, 6
(1977). 920--936.
[17] B. W. WEIBE, Statistical Methods in Algorithm Design and Analysis, Ph.D. Thesis, Carnegie-
Mellon University, Pittsburgh, Pennsylvania (August 1978); appeared as CMU Computer
Science Report CMU--CS--78--142.