Abstract 1 Introduction 2 The Proportional Knapsack Problem 3 The General Knapsack Problem 4 Conclusion References

Stealing from the Dragon’s Hoard

Matthias Gehnen ORCID Department of Computer Science, RWTH Aachen University, Germany Moritz Stocker111Corresponding Author ORCID Department of Computer Science, ETH Zurich, Switzerland
Abstract

We introduce the Online Unbounded Knapsack Problem with Removal, a variation of the well-known Online Knapsack Problem. Items, each with a weight and value, arrive online and an algorithm must decide on whether or not to pack them into a knapsack with a fixed weight limit. An item may be packed an arbitrary number of times and items may be removed from the knapsack at any time without cost. The goal is to maximize the total value of items packed, while respecting a weight limit. We show that this is one of the very few natural online knapsack variants that allow for competitive deterministic algorithms in the general setting, by providing an algorithm with competitivity 1.6911. We complement this with a lower bound of 1.5877.

We also analyze the proportional setting, where the weight and value of any single item agree, and show that deterministic algorithms can be exactly 3/2-competitive. Lastly, we give lower and upper bounds of 6/5 and 4/3 on the competitivity of randomized algorithms in this setting.

Keywords and phrases:
online problems, online knapsack, unbounded knapsack, removal
Copyright and License:
[Uncaptioned image] © Matthias Gehnen and Moritz Stocker; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Adversary models
Editors:
Meena Mahajan, Florin Manea, Annabelle McIver, and Nguyễn Kim Thắng

1 Introduction

Imagine, if you will, a hobbit creeping through a dragon’s lair. Having found the dragon, it now swiftly makes its escape. Surrounding it on its way out are piles of coins, heaps of rubies, mountains of diamonds, each containing far more than the hobbit could possibly carry. Grinning, the hobbit opens its trusty knapsack and fills it to the brim with silver coins. Around a corner, it almost stumbles over a number of large gold bars. It empties its knapsack of silver and packs two of these gold bars instead, which completely fill its knapsack. Around the next bend, gleaming in the light of the hobbit’s candle, lies an enormous jewel. Greedily, the hobbit removes the two gold bars and packs the jewel instead. It silently curses, wishing it had kept the silver coins, some of which would have nicely filled up the remaining space in the knapsack. But it dares not go back, deeper into the lair, towards the dormant dragon. And thus, the hobbit shoulders its knapsack and presses on…

In the Online Knapsack Problem, an algorithm receives an unknown number of items one by one, each with a weight and a value. It must decide whether or not to pack these items into a knapsack, without any knowledge about future items that may be offered. Its goal is to maximize the combined value of the items it packs without exceeding the knapsack’s weight capacity, often normalized to 1.

Ever since the problem was introduced by Marchetti-Spaccamela and Vercellis [14], it has offered fertile ground for analysis. Though the original problem is not competitive, even for the Proportional Knapsack variant where the weight and value of any single item are equal, there are countless variants of the problem and aspects under which to consider them that prove interesting – and for which well-performing algorithms exist. A recent survey detailing many of these results has been compiled by Böckenhauer et al. [4].

One of the simplest competitive variants is the Online Knapsack Problem with Removal. In this model, items may be removed from the knapsack at any time without cost. It was first studied for the proportional case by Iwama and Taketomi [10], who showed that the best competitive ratio that can be achieved by a deterministic algorithm is exactly the golden ratio φ1.618. Han et al. [7] considered randomized algorithms and provided an algorithm with competitivity 10/7. They also gave a lower bound of 5/4 on the competitive ratio of any randomized algorithm, which has recently been improved by Hächler [6] to approximately 1.2695. The general case, where items have arbitrary weights and values remains non-competitive for deterministic algorithms even with removal, as shown by Iwama and Zhang [11]. However, Han et al. [7] showed that a competitivity of 2 can in fact be achieved by randomized algorithms, which they complemented by a lower bound of 1+1/e.

More recently, Böckenhauer et al. [3] considered the Online Unbounded Knapsack Problem. This can be seen as the “industrial” setting of the knapsack problem, where each item is available in unlimited quantities. In this model, rather than only being able to decide on whether to pack an item or not, an algorithm may choose to pack it any number of times. The classical model, where each item can only be packed once or not at all is correspondingly sometimes referred to as the 0-1 Knapsack Problem. More correctly, the Unbounded Knapsack Problem should not be viewed as a model that provides additional resources to an algorithm, but as one that limits the possible instances considered. An instance of the Unbounded Knapsack Problem is equivalent to one of the 0-1 Knapsack Problem where any item of weight w is guaranteed to consecutively appear at least 1/w times. Böckenhauer et al. showed that deterministic algorithms can be exactly 2-competitive in the proportional case, and gave upper and lower bounds of 1+ln(2)1.6931 and 1.7353, respectively, for randomized algorithms. They also showed that in the general setting, no finite competitive ratio is possible even for randomized algorithms.

Our Contributions

In this paper, we combine the Online Unbounded Knapsack Problem and the Online Knapsack Problem with Removal to the Online Unbounded Knapsack Problem with Removal. This can be interpreted as an application of removal, being one of the most natural variants of the knapsack problem, to the industrial setting of the Unbounded Knapsack, resulting in a situation where an algorithm is not penalized for initially being forced to pack worthless items.

More whimsically, it can be described by a hobbit stealing from the riches of a dragon’s hoard. The online nature of the problem is captured by the fact that the hobbit’s first priority is to move away from the dragon, while it tries to maximize the value of items it takes along. It is natural to assume that the hobbit would be able to remove items from its knapsack. Given that a dragon’s hoard is commonly associated with untold riches in vast quantities, the unbounded setting is also a reasonable choice.

In this model, we show that the best possible competitive ratio for deterministic algorithms in the proportional variant is exactly 3/2 (Lemmas 3 and 2). For randomized algorithms, we offer a simple lower bound of 6/5 on the competitive ratio (Lemma 4) and a slightly more complex randomized algorithm with competitivity 4/3 (Theorem 5). These results are summarized in Table 1. Since this model is obviously no harder than the Online Unbounded Knapsack Problem (lending additional capabilities to the algorithm) and the Online Knapsack Problem with Removal (essentially limiting the set of possible instances), it is not surprising that all our bounds are lower than the best-known bounds in those models.

Our main results concern the General Knapsack Problem, however. Interestingly, the Online Unbounded Knapsack Problem with Removal is one of the few natural knapsack variants where deterministic algorithms can be competitive without further assumptions.222The few other problems that allow for this include Online Knapsack with Removal with resource augmentation [11] and resource buffer [8], as well as Online Multiple Knapsack with Removal [5], all of which tinker with the size of the knapsack and are arguably less simple than the variant we consider. Neither the Online Knapsack Problem with Removal alone [11] nor the Online Unbounded Knapsack Problem (without removal) [3] allow for this behavior. However, we show that in the combined model of the Online Unbounded Knapsack Problem with Removal, a simple algorithm can achieve a competitivity of 1.6911 (Theorem 9). We complement this with a lower bound of 1.5877 (Theorem 11).

Table 1: Results contained in this paper (left column), as compared to previous results for Online Unbounded Knapsack and Online Knapsack with Removal. These results cover deterministic and randomized algorithms for the proportional case, as well as deterministic algorithms for the general case. Randomized algorithms for the general problem are not studied separately in this paper. The lower bound follows from the proportional case, while the upper bound follows from the deterministic case.
Unbounded with Removal Unbounded [3] With Removal
lower bound upper bound l.b. u.b. l.b. u.b.
prop. det. 3/2 (Lemma 3) 3/2 (Lemma 2) 2 1.618 [10]
prop. rand. 6/5 (Lemma 4) 4/3 (Thm. 5) 1.6931 1.7353 1.2695[6] 10/7[7]
general det. 1.5877 (Thm. 11) 1.6911 (Thm. 9) [11]
general rand. 6/5 (Lemma 4) 1.6911 (Thm. 9) 1.3679 [7] 2 [7]

Preliminaries

An instance of the Online Unbounded Knapsack Problem with Removal consists of a sequence of items I=(x1,,xn). An item is given as x=(w,v), where w=w(x) is its weight and v=v(x) is its value; we define the item’s density as ρ(x)=v(x)/w(x).

A solution is given as a multiset S of items, such that xI for any xS, satisfying

xSw(x)1.

The goal is to maximize the gain

v(S)=xSv(x).

We denote by Opt(I) an optimal solution to I, that is, a solution that maximizes v(Opt(I)).

An online algorithm Alg maintains a solution (or “knapsack”) S. When it receives an item x, it may add (or “pack”) any number of copies of x to S, then remove an arbitrary subset of items from S, such that S is again a valid solution. We denote by Alg(I) the solution of Alg on the instance I.

A deterministic algorithm Alg is said to be (strictly) c-competitive for some constant c1 if cv(Alg(I))v(Opt(I)) for any instance I. Equivalently, a randomized algorithm Alg is said to be (strictly) c-competitive in expectation if c𝔼[v(Alg(I))]v(Opt(I)) for any instance I. In either case, the (strict) competitive ratio or competitivity of Alg is defined as

infc1{cAlg is (strictly) c-competitive (in expectation)}.

There is also a non-strict version of competitivity: an algorithm is said to be (non-strictly) c-competitive if there exists a constant α0 such that cv(Alg(I))+αv(Opt(I)) for any instance I. Throughout this paper, we only consider the strict competitive ratio and reserve the term competitive ratio for this version. It should be noted, however, that the lower bound for general item values of Theorem 11 also holds for the non-strict version, which can easily be seen by scaling the values of all items. For any upper bound, proving a strict competitive ratio obviously implies a corresponding non-strict ratio.

For an item x=(w,v), the maximal number of copies of x that fit into the knapsack at the same time is exactly 1/w(x). We define the cumulative value v(x)=v(x)1/w(x) as the combined value of these copies, that is, the maximal gain that can be achieved using only copies of x. Similarly, we define the cumulative weight of x as w(x)1/w(x). We denote by fill(x) the corresponding multiset consisting of 1/w(x) copies of x.

We finally state a simple result that will prove useful throughout the paper:

Lemma 1.

If 0<x1/n, for n and n1, then

x1/x=1/x1/xnn+1.
Proof.

Let n=1/x, so 1/xn+1. Since 1/xn, clearly nn, and therefore

1/x1/x=n1/xnn+1nn+1.

2 The Proportional Knapsack Problem

In this section, we consider the Proportional Knapsack Problem, where the weight and value of any item are equal. For convenience, we identify an item x with its weight and value, that is, we say that x=w(x)=v(x).

2.1 Deterministic Algorithms

We start by considering a very simple algorithm:

The algorithm Simple keeps the heaviest item in the instance, as long as there are no items of weight less than or equal to 1/2. If there is an item of weight smaller than or equal to 1/2 in the instance, Simple removes any previous item in the knapsack, packs as many copies of this small item as possible and ignores all further items.

The algorithm is shown in pseudocode as Algorithm 1.

Algorithm 1 The deterministic algorithm Simple for the proportional knapsack problem.
Lemma 2.

The competitive ratio of Simple is at most 3/2.

Proof.

Consider any instance I. If there are no items of weight less than or equal to 1/2 in I, no two items in the instance fit in the knapsack together. Since Simple keeps the heaviest item, it is optimal.

Otherwise, let x be the first item in I of weight x1/2. By definition, Simple achieves a gain of x1/x, which is at least 2/3 by Lemma 1. Since the optimal solution has value at most 1, Simple therefore has a competitive ratio of at most 3/2.

While, as its name indicates, Simple uses a straightforward strategy, we can show that no deterministic online algorithm can improve on its competitive ratio.

Lemma 3.

No deterministic algorithm for the Proportional Online Unbounded Knapsack Problem with Removal can have a competitive ratio of less than 3/2.

Proof.

Let Alg be any online algorithm and let ε>0 be sufficiently small. Consider the two instances

I1 =(1/3+2ε,2/3ε,1/3+ε),
I2 =(1/3+2ε,2/3ε,2/32ε).

Since I1 and I2 agree on the first two items, Alg must act identically on that prefix. If it packs the second item 2/3ε, it cannot keep any copies of 1/3+2ε. In this case, it has a gain of at most 2/3ε on I2, while by packing one copy of 1/3+2ε and the last item, a gain of 1 would have been possible.

If, on the other hand, it does not pack the item 2/3ε, it cannot pack more than two copies of 1/3+2ε and 1/3+ε in total. Therefore, its gain on I1 is at most 2/3+4ε, while again, a gain of 1 is possible by packing the second item and one copy of the last item. In either case, its competitive ratio is at least 1/(2/3+4ε). The statement of the lemma follows as ε0.

2.2 Randomized Algorithms

We now consider randomized algorithms for the Proportional Online Unbounded Knapsack Problem with Removal. We start with a simple lower bound using Yao’s principle [19]:

Fact (Yao’s Principle).

Consider any online maximization problem, where v(S) denotes the value of a solution S. Let be a set of instances, and let Prob denote any probability distribution on , with 𝔼 being the corresponding expectation. If, for any deterministic algorithm Alg, it holds that

c𝔼[v(Alg)]𝔼[v(Opt)],

for some constant c1, then no randomized algorithm for the problem can have a competitive ratio of less than c.

A more detailed explanation of Yao’s principle can be found, for example, in the textbook by Komm [12].

Lemma 4.

No randomized algorithm for the Proportional Online Unbounded Knapsack Problem with Removal can have a competitive ratio of less than 6/5.

Proof.

The proof uses the same instances as in Lemma 3, that is,

I1 =(1/3+2ε,2/3ε,1/3+ε),
I2 =(1/3+2ε,2/3ε,2/32ε),

for some sufficiently small ε>0. Let Alg be any deterministic algorithm that receives I1 or I2 each with probability 1/2. Then, as in the proof of Lemma 3, if Alg packs the item 2/3ε, its gain is at most 2/3ε on I2 and at most 1 on I1. If it does not pack the item 2/3ε, its gain is at most 2/3+4ε on I1 and at most 1 on I2. In either case, its expected gain is at most 1/2(2/3+4ε+1)=5/6+2ε, while the optimal solution is always 1. Therefore, by Yao’s principle, no randomized algorithm can have a competitive ratio of less than (5/6+2ε)1. The statement of the lemma follows as ε0.

We now present a randomized algorithm for the Proportional Online Unbounded Knapsack Problem with Removal that uses a single random bit and has a competitive ratio of at most 4/3.

The algorithm RandChoice divides items into four different weight categories. Good items G=[0,1/3][3/8,1/2][3/4,1], small items S=]1/3,3/8[, medium items M=]1/2,5/8[, and large items L=[5/8,3/4[. It chooses uniformly at random between two deterministic strategies A1 and A2. In both strategies, if it encounters an item in G, it removes any items in the knapsack, packs the new item as often as possible and ignores all further items. Otherwise the corresponding strategies are as follows:

  • 𝑨𝟏:RandChoice initially keeps copies of a single item, in the following order of priority:

    1. 1.

      Two copies of the smallest item in S encountered so far,

    2. 2.

      The largest item in M encountered so far (if none in S are present),

    3. 3.

      The smallest item in L encountered so far (if none in SM are present).

    To do so, it removes any previous items in the knapsack if necessary.

    If at any point it encounters an item from S that fits with an item in ML that is already in the knapsack or vice versa, it packs one copy of each. From then on, it replaces the item in S with any smaller item from S if possible, and the item from ML with a larger item from ML if it can do so without removing the item from S.

  • 𝑨𝟐: RandChoice initially keeps copies of a single item, in the following order of priority:

    1. 1.

      The smallest item in L encountered so far,

    2. 2.

      Two copies of the smallest item in S encountered so far (if none in L are present),

    3. 3.

      The largest item in M encountered so far (if none in SL are present).

    To do so, it removes any previous items in the knapsack if necessary.

    If at any point it encounters an item from S that fits with an item in L (but not M) that is already in the knapsack or vice versa, it packs one copy of both and ignores all further items in SML.

The algorithm is shown in pseudocode as Algorithm 2.

Theorem 5.

RandChoice achieves a competitive ratio of at most 4/3.

Proof.

Let I be any non-empty instance and let OptOpt(I) be a fixed optimal solution of value v(Opt). We first consider what happens when there is an item from G in the instance. Let gG be the first such item. In that case, RandChoice achieves a gain of g1/g. If g[0,1/3], this is at least 3/4 by Lemma 1. If g[3/8,1/2], we know that g1/g=2g3/4. If g[3/4,1], RandChoice also achieves a gain of at least 3/4. In any case, its competitive ratio is at most 4/3. We can therefore assume that I only contains items in SML. Additionally, if I contains only items from M, then RandChoice is clearly optimal since both strategies keep the largest such item in this case. We therefore also assume that I contains an item from SL.

If v(Opt)3/4, then RandChoice is easily seen to be 4/3-competitive: Strategy A1 always achieves a gain of at least 1/2 and, since the instance contains an item from SL, Strategy A2 achieves a gain of at least 5/8 (any item from S has a cumulative value of at least 2/3>5/8). The expected gain of RandChoice is therefore at least 1/2(1/2+5/8)=9/16, and its competitive ratio in expectation is at most (3/4)/(9/16)=4/3. We can therefore assume that v(Opt)>3/4, which means that Opt contains one copy of an item sS and one copy of an item bML. We will now distinguish three different cases:

  • Case 1 (bM):Since there is an item from SL in the instance, as above, Strategy A2 will achieve a gain of at least 5/85/8v(Opt). Since any item from S fits with any item from M, and since it prioritizes items from SM over items from L, Strategy A1 will pack both an item from S and an item from ML. More specifically, since it first prioritizes larger items from M and then replaces the item from ML with larger items if possible, it packs an item from S and an item of size at least b, leading to a gain of at least 1/3+b. On the other hand, v(Opt)3/8+b. Therefore, Strategy A1 achieves a gain of at least (1/3+b)/(3/8+b)v(Opt). Since (1/3+b)/(3/8+b) increases with b, the gain of Strategy A1 is at least (1/3+1/2)/(3/8+1/2)v(Opt)=20/21v(Opt). Combining Strategies A1 and A2, the algorithm RandChoice has an expected gain of 1/2(5/8+20/21)v(Opt)=265/336v(Opt)>3/4v(Opt).

  • Case 2 (bL and s arrives before b): As in the previous case, Strategy A2 achieves a gain of at least 5/8. By definition of Strategy A1, it will have packed an item from S of size at most s when b arrives, possibly together with an item from ML. This means that it could pack b together with that item, and since it replaces the item from ML with a larger item if possible, it has a gain of at least 1/3+b1/3+5/8=23/24. This means that RandChoice has an expected gain of at least 1/2(5/8+23/24)=19/24>3/4.

  • Case 3 (bL and b arrives before s): Since the instance contains an item from S, Strategy A1 achieves a gain of at least 2/3. Strategy A2 on the other hand is always able to pack both an item from S and an item from L: if it still has only one item packed when s arrives, that item must be an item from L of size at most b. Therefore, Strategy A2 achieves a gain of at least 1/3+5/8=23/24 and RandChoice achieves an expected gain of at least 1/2(2/3+23/24)=13/16>3/4.

In any case, RandChoice has an expected gain of at least 3/4v(Opt) and thus a competitive ratio in expectation of at most 4/3.

It may seem that the competitive ratio of RandChoice can easily be improved by not choosing the two strategies uniformly. The competitive ratio of either strategy is however bounded from above by 4/3 by the assumptions made before the case distinction and especially by the way they deal with items from G. For example, if the first item Simple receives has weight 3/4, it will pack it and ignore all future items, while the optimal solution might well be 1.

Though it may be possible to improve the algorithm, this would thus require a more fine-grained treatment of the items in G.

Algorithm 2 The randomized algorithm RandChoice for the proportional knapsack problem.

3 The General Knapsack Problem

We now consider the general case of the problem, where the value of an item may be unrelated to its weight. We first show that there are in fact competitive deterministic algorithms for the General Online Unbounded Knapsack Problem with Removal, which may come as a surprise, given that most variants of the General Online Knapsack Problem remain non-competitive [11], many of them even for randomized algorithms [2, 3]. To this end, consider an algorithm Focus.

The algorithm Focus only keeps copies of a single item of maximal cumulative value. If an item of higher cumulative value arrives, it removes all items in the knapsack and packs as many copies of this new item as possible.

The algorithm is shown in pseudocode as Algorithm 3. Note that if Focus is used in an instance of the Proportional Online Knapsack Problem, its gain is at least that of the algorithm Simple from Section 2.1, which also only keeps copies of a single item. Therefore, Focus also achieves the best possible competitive ratio of 3/2 in the proportional case.

Algorithm 3 The deterministic algorithm Focus for the general knapsack problem.

To analyze the competitivity of Focus in the general case, we define a series of numbers an for n1 recursively by

a1=2,an=1+i=1n1aifor n2. (1)

The following properties of this sequence333The sequence, whose first elements are 2,3,7,43,1807,, is known as Sylvester’s sequence (sequence A000058 in the OEIS [15]) after James Joseph Sylvester, who studied a family of unit fractions related to it [18]. can be easily verified by induction:

Lemma 6.

For any n1,

  1. (i)

    an+1=an(an1)+1 ,

  2. (ii)

    1an1=1j=1n11aj .

Now let N1. We further define

SN =n=1N(an1)1,with S0=0,
TN =aN(aN1)2+SN1.

Lastly, we define S=n=1(an1)1; clearly, SNS as N. Since the numbers an grow indefinitely, we also know that aN/(aN1)20, and thus also TNS as N. Furthermore, the numbers TN satisfy the following two properties:

Lemma 7.

For any N1 and 1kN,

  1. (i)

    (aN1)2aN(1SN1/TN)=TN1.

  2. (ii)

    ak(ak1)ak+1(1Sk1/TN)>TN1.

Proof.

Property ˜(i) follows directly from the definition of TN, since

TNSN1=aN(aN1)21SN1/TN=aN(aN1)2TN1.

We will prove ˜(ii) by induction on k, starting with k=N. We first convince ourselves that for k=N,

aN(aN1)aN+1(1SN1/TN)>(aN1)2aN(1SN1/TN)=TN1

by ˜(i). Now let 1k<N and assume by induction that ˜(ii) holds for k+1. Then

ak(ak1)ak+1(1Sk1/TN)TN1
= ak(ak1)ak+1(1Sk1/TNak+1ak(ak1)TN1)
= ak(ak1)ak+1(1Sk1/TN1ak1TN11ak(ak1)TN1)
= ak(ak1)ak+1(1(Sk1+1ak1)TN11ak(ak1)TN1)
= ak(ak1)ak+1(1Sk/TN1ak(ak1)TN1)
= ak(ak1)ak+1(1Sk/TN)1ak+1TN1
> ak(ak1)ak+1ak+1+1ak+1(ak+11)TN11ak+1TN1(by induction)
= TN1(ak+11ak+1ak+1+1ak+1(ak+11)1ak+1)(by Lemma 6˜(i))
= TN1(ak+1+1(ak+1)ak+11ak+1)
= TN1(ak+1)ak+1>0,

which means that

ak(ak1)ak+1(1Sk1/TN)>TN1.

By induction, property ˜(ii) holds for all 1kN.

Before we state and prove the competitivity of Focus, we give one final preparatory lemma.

Lemma 8.

Let A be any multiset of items in an instance with xAw(x)1. Let v(A)=xAv(x) and let xd=(wd,vd) be an item of maximal density in A. Then Focus will achieve a gain of at least v(A)1/wd1/wd on that instance.

Proof.

We know that

v(A)=xAv(x)=xAv(x)w(x)w(x)xAvdwdw(x)vdwd.

The cumulative value of xd satisfies

v(xd)=vd1/wdv(A)1/wd1/wd.

Since Focus keeps an item of maximal cumulative value, it will definitely achieve such a gain.

Theorem 9.

Focus achieves a competitive ratio of at most S<1.69104.

Proof.

Let I be any instance and let OptOpt(I) be an optimal solution on I. We first start with an intuitive idea of the proof. Ideally, an optimal solution would fill all of its space in the knapsack optimally with the densest possible items. Lemma 8 means that the higher the cumulative weight of the densest item in Opt, the better the competitive ratio of Focus. The smallest cumulative weight that any item can have is at least 1/2, so we assume this as a worst-case scenario. By definition, the gain of Focus is at least the value of that item. Then we can consider the second-densest item in Opt. Since it must have weight smaller than 1/2, it can be packed at least twice and thus its value can be at most 1/2 the gain of Focus. The smallest cumulative weight such an item can have is at least 2/3, corresponding to a weight of at least 1/3, which we again assume as a worst-case scenario. We then continue to the third-densest item, which must have a weight of at most 11/21/3=1/6, and so its value can be at most 1/6 the gain of Focus. We can continue this process arbitrarily and see that the value of Opt is at most 1+1/2+1/6+=S times the gain of Focus.

More formally, we normalize the values of all items such that v(Opt)=1. Let N1. We show that the algorithm has a gain of at least TN1 and thus a competitive ratio of at most TN on I. The statement of the theorem then follows since TNS as N. We first assume that this is not the case, that is, that the algorithm has a gain of strictly less than TN1. From this, we inductively construct a series of items y1=(w1,v1),,yN=(wN,vN) with the following properties:

  • The optimal solution Opt contains exactly one copy of each item yk.

  • The weight of yk is bounded by 1/ak<wk1/(ak1) for each 1kN.

  • The value of yk is bounded by vk<(TN(ak1))1 for each 1kN.

We first define y1=(w1,v1) as an item of maximal density in Opt. If w11/2, then by Lemmas 8 and 1, Focus achieves a gain of at least 2/3. Recall that a1=2 and S0=0, so the gain of Focus is at least

2/3=a1(a11)a1+1(1S0/TN)>TN1

by Lemma 7, which we assumed was not the case. This means that w1>1/2=1/a1, which also means that the optimal solution can contain only one copy of y1. If v1TN1, the algorithm achieves a gain of at least TN1, so v1<TN1=(TN(a11))1, which means that y1 satisfies the properties listed above.

Now assume by induction that we have defined y1,,yk1 satisfying these conditions for kN. Since these items are all part of the optimal solution, the other items in Opt must have a combined value of at least 1j=1k1vj>1j=1k1(TN(aj1))1=1Sk1/TN. They must also have a combined weight of at most 1j=1k1wj<1j=1k11/aj=1/(ak1) by Lemma 6˜(ii). This means that it would be possible to pack the combination of all items in Opt\{y1,,yk1} a total of ak1 times for a gain of at least (ak1)(1Sk1/TN). Now let yk=(vk,wk) be an item of maximal density among these items, so clearly also wk<1/(ak1). By Lemma 8, Focus achieves a gain of at least 1/wk1/wk(ak1)(1Sk1/TN). If wk1/ak, then by Lemma 1, its gain is at least akak+1(ak1)(1Sk1/TN)>TN1 by Lemma 7, which we assumed was not the case. Therefore, wk>1/ak, which also means that the optimal solution can contain only one copy of yk, since it would otherwise contain items of combined weight at least

(j=1k1wj)+2wk>(j=1k11aj)+21ak(j=1k11aj)+1ak1=1,

where the last equality follows from Lemma 6˜(ii).

Since wk1/(ak1), the item yk can be packed at least ak1 times by itself. Therefore, if vk(TN(ak1))1, then Focus achieves a gain of at least TN1, which we assumed was not the case, so vk<(TN(ak1))1. Therefore, yk satisfies all the properties above.

This means that we can construct y1,,yN satisfying these properties. Further note that in the case k=N we showed that Focus achieves a gain of at least 1/wN1/wN(aN1)(1SN1/TN). By Lemma 1, this is at least

aN1aN(aN1)(1SN1/TN),

which is equal to TN1 by Lemma 7˜(i), once again contradicting our assumption. We are forced to conclude that this assumption was wrong. The algorithm Focus will therefore always achieve a gain of at least TN1 and thus a competitive ratio of at most TN.

We know show that this bound is tight, that is, Focus does not achieve a better competitive ratio.

Lemma 10.

The competitive ratio of Focus is at least S.

Proof.

Consider the instance IN consisting of items xi=(wi,vi) for 1iN with wi=1/ai+ε for some 0<ε<(N(aN+11))1 and vi=1ai1. The item xi can be packed (ai1) times, so its cumulative value is given by (ai1)vi=1. The gain of Focus will therefore always be 1 on IN. On the other hand, there is a solution consisting of a single copy of each of the N items, since (i=1N1/ai)+Nε=11/(aN+11)+Nε<1 by Lemma 6˜(ii). This solution has a value of SN=i=1N1/(ai1), so Focus has a competitive ratio of at least SN on IN. The statement of the lemma follows as N.

The lower bound of Lemma 10 only holds for the specific, simple algorithm Focus. We now give a lower bound for the general case that improves upon the one implied by the proportional setting (Lemma 3). The proof once again makes use of the Sylvester numbers an defined in Equation 1.

Theorem 11.

Let N3. No deterministic algorithm for the General Unbounded Knapsack Problem with Removal can have a better competitive ratio than cN, where cN,v1,,vN solve the following system of equations:

vN =1
cN =vi1+viai1vi for 3iN (2)
cN =v2+v1/2v1 (3)
cN =v2+v1/2+i=3Nviai1v2 (4)
cN 1

In particular, no deterministic algorithm can have a competitive ratio better than c5>1.5877.

Proof.

Let Alg be any deterministic algorithm and let ε>0 be sufficiently small. Assume by contradiction that the competitive ratio of Alg is strictly less than cN. The following process is illustrated in Figure 1.

For i=N,,3, the algorithm receives first an item xi=(1/ai+2ε,vi/(ai1)) and then an item yi=(11/aiε,vi1).

Given that Alg holds only a single copy of yi+1 when xi arrives (or no items in the case of i=N), we can assume without loss of generality that it removes any items in the knapsack and packs ai1 copies of xi, since that configuration of items is strictly preferable: it achieves the same gain with a smaller weight, and yi+1 cannot be subdivided. It cannot pack both the item yi+1 and a copy of xi, since (11/ai+1ε)+(1/ai+2ε)>1.

We now claim that whenever an item yi arrives, Alg must remove all copies of xi from the knapsack and pack a single copy of yi. Otherwise, consider the first item yi that Alg does not pack. In that case, Alg now receives an item xi=(1/ai+ε,vi/(ai1)). A solution consisting of yi and a single copy of xi would achieve a gain of vi1+vi/(ai1). However, since Alg can only pack a combined total of ai1 copies of xi and xi, it has a gain of at most vi. Therefore, it has a competitive ratio of at least (vi+vi+1/(ai1))/vi=cN by Equation 2.

This process continues until Alg has packed a single copy of the item y3=(11/a3ε,v2)=(6/7ε,v2). It then receives an item x2=(1/3+2ε,v1/2). Note that we cannot assume as before that Alg packs this item, since the values of these two items are unrelated a priori. However, if it does not pack the item x2, Alg receives an item z=(1/2+ε,v2). The best gain it can then achieve is v2. Packing a single copy of each of z,x2,x3,,xN is possible, since i=1N1/ai<1 by Lemma 6˜(ii). This leads to an optimal gain of at least v2+v1/2+i=1Nvi/(ai1), and thus to a competitive ratio of cN by Equation 4.

If it packs the item x2, Alg now receives an item y2=(2/3ε,v2). If it does not pack y2, Alg receives an item x2=(1/3+ε,v1). The best gain it can achieve is v1, while packing a single copy each of x2 and y2 is possible, leading to a competitive ratio of at least (v2+v1/2)/v1=cN by Equation 3. Finally, if it does pack y2, Alg again receives an item z=(1/2+ε,v2). As before, the best gain it can achieve is v2, while packing a single copy each of z,x2,,xN is possible, leading to a competitive ratio of cN by Equation 4.

Figure 1: Illustration of the process used in the proof of Theorem 11, indicating which of the conditions (2), (3), or (4) leads to the desired competitive ratio of cN.

To solve the system of equations, note that Equation 2 implies that vi1=(cN1/(ai1))vi for 3iN, and Equation 3 implies that v1=v2/(cN1/2). With the additional condition of vN=1, this means that

vi =j=i+1N(cN1aj1)for i2 (5)
v1 =(cN1/2)1v2 (6)

Equation 4 then becomes

cNv2=v2+v12+i=3Nviai1 (cN1)v2=(6)(cN1/2)1v22+i=3Nviai1
(cN1)(cN1/2)v2=v22+(cN1/2)i=3Nviai1.

Using the expressions for vi from Equation 5 and the fact that 1=1/(a11) and 1/2=1/(a21), this becomes

i=1N(cN1ai1)=12i=3N(cN1ai1)+(cN1/2)i=3N1ai1j=i+1N(cN1aj1). (7)

This is a polynomial equation of degree N, which can be solved numerically for fixed values of N. In the special case of N=5, we find that the largest positive root of Equation 7 is c5>1.5877.

4 Conclusion

We have introduced and studied the Online Unbounded Knapsack Problem with Removal. Apart from showing that the competitive ratio that can be achieved by deterministic algorithms in the proportional setting is exactly 3/2, we also gave lower and upper bounds of 6/5 and 4/3, respectively, for randomized algorithms.

We further showed that deterministic algorithms can be competitive in the general setting and provided upper and lower bounds of approximately 1.5877 and 1.6913 on their competitive ratio. Given the simple nature of the algorithm Focus, it does not seem unreasonable that an algorithm with a better competitive ratio exists. It might be worth considering randomized algorithms in the general setting, improving on the implied bounds shown in Table 1.

A Possible Connection to Bin-Packing

Both the upper bound of Theorem 9 and the lower bound of Theorem 11 depend on the Sylvester numbers (an)n=1 defined in Equation 1. The upper bound, which is explicitly given as S=n=1(an1)1, is of particular interest, since this is not the first time that S has appeared as the competitive ratio of an online algorithm for a packing problem: it was previously shown to be the (asymptotic) competitive ratio of the Harmonic algorithm for Bin-Packing [13].

Any speculation that the problems of Bin-Packing and Online Unbounded Knapsack with Removal might have the same competitivity is moot, since the best known algorithm for Bin-Packing due to Balogh et al. [1] has competitivity at most 1.5783, which beats the lower bound of 1.5877 we proved in Theorem 11. However, the Harmonic algorithm is part of a larger family, the Super-Harmonic framework introduced by Seiden [17]. The best-known lower and upper bounds for algorithms in this framework are 1.5833 [16] and 1.5884 [9], respectively, which tantalizingly frame our lower bound. It is therefore at least theoretically possible that the best competitive ratios of an algorithm in the Super-Harmonic framework and an algorithm for Online Unbounded Knapsack with Removal agree.

If there is some connection between the two problems, further research might provide deeper insight into the competitive analysis of both problems. Potentially, this could lead to reducing the gap between the upper and lower bounds of the Super-Harmonic framework, or even closing it. However, this is of course mere speculation:

  1. (a)

    There is no reason to assume that the true competitive ratio of the Online Unbounded Knapsack Problem with Removal is closer to the lower bound of 1.5877 than the upper bound of 1.6911.

  2. (b)

    Even if this were the case, and the competitive ratios of the two problems are close together, there is a priori no reason for them to agree.

  3. (c)

    Even if the ratios happen to agree, this might not necessarily be due to some deeper connection between the two problems.

Even so, we find this numerical coincidence between the two online packing problems to be worth noting. The possibility of such a connection remains an open problem. It could be answered in the negative by even a comparatively small improvement of the lower bound of Theorem 11.

References

  • [1] János Balogh, József Békési, György Dósa, Leah Epstein, and Asaf Levin. A New and Improved Algorithm for Online Bin Packing. In Yossi Azar, Hannah Bast, and Grzegorz Herman, editors, 26th Annual European Symposium on Algorithms (ESA 2018), volume 112 of Leibniz International Proceedings in Informatics (LIPIcs), pages 5:1–5:14, Dagstuhl, Germany, 2018. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.ESA.2018.5.
  • [2] Hans-Joachim Böckenhauer, Dennis Komm, Richard Královič, and Peter Rossmanith. The online knapsack problem: Advice and randomization. Theoretical Computer Science, 527:61–72, 2014. doi:10.1016/j.tcs.2014.01.027.
  • [3] Hans-Joachim Böckenhauer, Matthias Gehnen, Juraj Hromkovič, Ralf Klasing, Dennis Komm, Henri Lotze, Daniel Mock, Peter Rossmanith, and Moritz Stocker. Online unbounded knapsack. Theory of Computing Systems, 69(1):1–25, 2025. doi:10.1007/s00224-025-10215-0.
  • [4] Hans-Joachim Böckenhauer, Juraj Hromkovič, Dennis Komm, Peter Rossmanith, and Moritz Stocker. A survey of online knapsack problems. Discrete Applied Mathematics, 378:492–507, 2026. doi:10.1016/j.dam.2025.08.011.
  • [5] Marek Cygan, Lukasz Jez, and Jirí Sgall. Online knapsack revisited. Theory of Computing Systems, 58(1):153–190, 2016. doi:10.1007/s00224-014-9566-4.
  • [6] Valentin Hächler. Untrusted predictions for knapsack problem variants. Bachelor’s Thesis, ETH Zurich, 2025. doi:10.3929/ethz-c-000782659.
  • [7] Xin Han, Yasushi Kawase, and Kazuhisa Makino. Randomized algorithms for online knapsack problems. Theoretical Computer Science, 562:395–405, 2015. doi:10.1016/j.tcs.2014.10.017.
  • [8] Xin Han, Yasushi Kawase, Kazuhisa Makino, and Haruki Yokomaku. Online knapsack problems with a resource buffer. In Pinyan Lu and Guochuan Zhang, editors, 30th International Symposium on Algorithms and Computation (ISAAC 2019), volume 149 of LIPIcs, pages 28:1–28:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2019. doi:10.4230/LIPIcs.ISAAC.2019.28.
  • [9] Sandy Heydrich and Rob van Stee. Beating the harmonic lower bound for online bin packing. In Ioannis Chatzigiannakis, Michael Mitzenmacher, Yuval Rabani, and Davide Sangiorgi, editors, 43rd International Colloquium on Automata, Languages, and Programming, ICALP 2016, July 11-15, 2016, Rome, Italy, volume 55 of LIPIcs, pages 41:1–41:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2016. doi:10.4230/LIPIcs.ICALP.2016.41.
  • [10] Kazuo Iwama and Shiro Taketomi. Removable online knapsack problems. In Peter Widmayer, Francisco Triguero Ruiz, Rafael Morales Bueno, Matthew Hennessy, Stephan J. Eidenbenz, and Ricardo Conejo, editors, 29th International Colloquium on Automata, Languages and Programming (ICALP 2002), volume 2380 of Lecture Notes in Computer Science, pages 293–305. Springer, 2002. doi:10.1007/3-540-45465-9_26.
  • [11] Kazuo Iwama and Guochuan Zhang. Online knapsack with resource augmentation. Information Processing Letters, 110(22):1016–1020, 2010. doi:10.1016/j.ipl.2010.08.013.
  • [12] Dennis Komm. An Introduction to Online Computation – Determinism, Randomization, Advice. Springer, 2016. doi:10.1007/978-3-319-42749-2.
  • [13] C. C. Lee and D. T. Lee. A simple on-line bin-packing algorithm. J. ACM, 32(3):562–572, 1985. doi:10.1145/3828.3833.
  • [14] Alberto Marchetti-Spaccamela and Carlo Vercellis. Stochastic on-line knapsack problems. Mathematical Programming, 68:73–104, 1995. doi:10.1007/BF01585758.
  • [15] OEIS Foundation Inc. The On-Line Encyclopedia of Integer Sequences, 2026. Published electronically at http://oeis.org.
  • [16] Prakash Ramanan, Donna J Brown, C.C Lee, and D.T Lee. On-line bin packing in linear time. Journal of Algorithms, 10(3):305–326, 1989. doi:10.1016/0196-6774(89)90031-X.
  • [17] Steven S. Seiden. On the online bin packing problem. J. ACM, 49(5):640–671, 2002. doi:10.1145/585265.585269.
  • [18] J. J. Sylvester. On a point in the theory of vulgar fractions. American Journal of Mathematics, 3(4):332–335, 1880. doi:10.2307/2369261.
  • [19] Andrew C.-C. Yao. Probabilistic computations: Toward a unified measure of complexity (extended abstract). In Proceedings of the 18th Annual Symposium on Foundations of Computer Science (FOCS 1977), pages 222–227, 1977. doi:10.1109/SFCS.1977.24.