An Efficient Fully Polynomial Approximation Scheme for the Subset-Sum Problem
Total Page:16
File Type:pdf, Size:1020Kb
View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by Elsevier - Publisher Connector Journal of Computer and System Sciences 66 (2003) 349–370 http://www.elsevier.com/locate/jcss An efficient fully polynomial approximation scheme for the Subset-Sum Problem Hans Kellerer,a,à Renata Mansini,b Ulrich Pferschy,a and Maria Grazia Speranzac a Institut fu¨r Statistik und Operations Research, Universita¨t Graz, Universita¨tsstr. 15, A-8010 Graz, Austria b Dipartimento di Elettronica per l’Automazione, Universita` di Brescia, via Branze 38, I-25123 Brescia, Italy c Dipartimento Metodi Quantitativi, Universita` di Brescia, Contrada S. Chiara 48/b, I-25122 Brescia, Italy Received 20 January 2000; revised 24 June 2002 Abstract Given a set of n positive integers and a knapsack of capacity c; the Subset-Sum Problem is to find a subset the sum of which is closest to c without exceeding the value c: In this paper we present a fully polynomial approximation scheme which solves the Subset-Sum Problem with accuracy e in time Oðminfn Á 1=e; n þ 1=e2 logð1=eÞgÞ and space Oðn þ 1=eÞ: This scheme has a better time and space complexity than previously known approximation schemes. Moreover, the scheme always finds the optimal solution if it is smaller than ð1 À eÞc: Computational results show that the scheme efficiently solves instances with up to 5000 items with a guaranteed relative error smaller than 1/1000. r 2003 Elsevier Science (USA). All rights reserved. Keywords: Subset-sum problem; Worst-case performance; Fully polynomial approximation scheme; Knapsack problem 1. Introduction Given a set of n items En ¼f1; y; ng each having a positive integer weight wj ð j ¼ 1; y; nÞ and a knapsack of capacity c; the Subset-Sum Problem (SSP) is to select a subset E of En such that the corresponding total weight wðEÞ is closest to c without exceeding c: Formally, the SSP ÃCorresponding author. E-mail addresses: [email protected] (H. Kellerer), [email protected] (R. Mansini), pferschy@ uni-graz.at (U. Pferschy), [email protected] (M.G. Speranza). 0022-0000/03/$ - see front matter r 2003 Elsevier Science (USA). All rights reserved. doi:10.1016/S0022-0000(03)00006-0 350 H. Kellerer et al. / Journal of Computer and System Sciences 66 (2003) 349–370 is defined as follows: Pn maximize wjxj j¼1 Pn subject to wjxjpc; xjAf0; 1gðj ¼ 1; y; nÞ; j¼1 ( 1 if item j is selected; where xj ¼ 0 otherwise: P n X y We assume, without loss of generality, that j¼1 wj c and wjpc for j ¼ 1; ; n: The SSP is a special case of the 0–1 Knapsack Problem arising when the profit and the weight associated with each item j are identical. A large number of theoretical and practical papers has appeared on this problem. An extensive overview on the literature is contained in the excellent book by Martello and Toth [18]. The SSP is well-known to be NP-hard [4]. Therefore, all exact algorithms for the SSP are pseudopolynomial. The classical dynamic programming approach has running time OðncÞ and requires OðncÞ memory. An optimal algorithm with improved complexity is due to Pisinger [19]. As for all NP-hard problems, it is interesting to look for suboptimal solutions which are within a predefined range of the optimal value, provided that the time and space requirements are reasonably small, i.e. bounded by a polynomial. The most common method to judge the quality of an approximationP algorithm is its worst-case à à performance. Define by X the optimal set of items and by z ¼ jAX à wj the optimal solution value of the SSP. Analogously, let X H be the set of items selected by a heuristic H and zH the corresponding solution value. A heuristic H for the SSP is an ð1 À eÞ-approximation algorithm ð0oeo1Þ if for any instance zH Xð1 À eÞzà ð1Þ holds. The parameter e is called the worst-case relative error.Afully polynomial approximation scheme is a heuristic H which, given an instance I and any relative error e; returns a solution value which obeys (1) and is polynomial both in the length of the encoded input and in 1=e: The first fully polynomial approximation scheme for the Subset-Sum Problem was suggested by Ibarra and Kim [8]. They partition the items into small and large items. The weights of the large items are scaled and then the problem with scaled weights and capacity is solved optimally through dynamic programming. The small items are added afterwards using a greedy-type algorithm. Their approach has time complexity Oðn Á 1=e2Þ and space complexity Oðn þ 1=e3Þ: Lawler [14] improved the scheme of Ibarra and Kim by a direct transfer of a scheme for the knapsack problem which uses a more efficient method of scaling. His algorithm has only Oðn þ 1=e4Þ time and Oðn þ 1=e3Þ memory requirement. Note that the special algorithm proposed in his paper for subset-sum does not work, since he makes the erroneous proposal to round up the item values. As an improvement, Lawler claims in his paper that a combination of his approach (which is 2 1 not correct) with a result by Karp [10] would give a running time of Oðn þ 1=e logðeÞÞ: Karp H. Kellerer et al. / Journal of Computer and System Sciences 66 (2003) 349–370 351 1þe 2 presents in [10] an algorithm for subset sum with running time nð e Þ log1þe 2 which is Oðn Á 1=e Þ: Lawler states that replacing n by the number of large items Oðð1=eÞ logð1=eÞÞ would give a running 2 1 1 time of Oðn þ 1=e logðeÞÞ: It can be easily checked that a factor of e is missing in the second term of the expression. Possibly, this mistake originates from the fact that there is a misprint in Karp’s 1þe 1þe paper, giving a running time of nð 2 Þ log1þe 2 instead of the correct nð e Þ log1þe 2: The approach by Gens and Levner [5,6] is based on a different idea. They use a dynamic programming procedure where at each iteration solution values are eliminated which are different from each other by at least a threshold value depending on e: The corresponding solution set is then determined by standard backtracking. Their algorithm solves the Subset-Sum Problem in Oðn Á 1=eÞ time and space. In 1994 Gens and Levner [7] presented an improved fully polynomial approximation scheme based on the same idea. The algorithm finds an approximate solution with relative error less than e in time Oðminfn=e; n þ 1=e3gÞ and space Oðminfn=e; n þ 1=e2gÞ: Our algorithm requires Oðminfn Á 1=e; n þ 1=e2 logð1=eÞgÞ time and Oðn þ 1=eÞ space. A short description of the algorithm has appeared as extended abstract in [13]. The paper is organized as follows: In Section 2 we first present the general structure of the algorithm in an informal way, afterwards our fully polynomial approximation scheme will be described extensively in a technical way. Its correctness, its asymptotic running time and its space requirements are analyzed in Section 3. Section 4 contains computational results and, finally, concluding remarks are given in Section 5. 2. The fully polynomial approximation scheme 2.1. Informal description of the algorithm As our approach is rather involved we try to give an intuition of the approximation scheme in an informal way. The detailed algorithm is presented in Section 2.2. We will explain the algorithm step by step starting from Bellmans procedure for calculating the optimal solution, then doing several modifications which yield better time and space requirements and finally reaching the FPTAS with the claimed time and space bounds. The well-known original dynamic programming approach by Bellman [1] solves the Subset- Sum Problem optimally in the following way: The set R of reachable values consists of integers i less than or equal to the capacity c for which a subset of items exists with total weight equal to i: Starting from the empty set, R is constructed iteratively in n iterations by adding in iteration j weight wj to all elements from R and keeping only partial sums not exceeding the capacity. For each value iAR a corresponding solution set with total weight equal to i is stored. This gives a pseudopolynomial algorithm with time OðncÞ and space OðncÞ: In order to obtain an FPTAS, the items are at first separated into small items (having weight pec) and large items. It can be seen easily that any ð1 À eÞ-approximation algorithm for the large items remains an ð1 À eÞ-approximation algorithm for the whole item set if we assign the small items in the end of the algorithm in a greedy way. (This is done in Step 4 of our algorithm.) Therefore, we will deal only with large items in the further considerations. The interval containing the large items ec; c is again partitioned into Oð1=eÞ subintervals of equal length ec (see Step 1). 352 H. Kellerer et al. / Journal of Computer and System Sciences 66 (2003) 349–370 J1n J1n Then, from each subinterval Ij :¼ jec; ð j þ 1Þec the (at most) ej À 1 smallest and ej À 1 biggest items are selected. All these large items are collected in the so-called set of relevant items L and the other items are discarded (see Step 2).