Improved Online Algorithms for Knapsack and GAP in the Random Order Model

The knapsack problem is one of the classical problems in combinatorial optimization: Given a set of items, each specified by its size and profit, the goal is to find a maximum profit packing into a knapsack of bounded capacity. In the online setting, items are revealed one by one and the decision, if the current item is packed or discarded forever, must be done immediately and irrevocably upon arrival. We study the online variant in the random order model where the input sequence is a uniform random permutation of the item set. We develop a randomized (1/6.65)-competitive algorithm for this problem, outperforming the current best algorithm of competitive ratio 1/8.06 (Kesselheim et al. in SIAM J Comput 47(5):1939–1964, 2018). Our algorithm is based on two new insights: We introduce a novel algorithmic approach that employs two given algorithms, optimized for restricted item classes, sequentially on the input sequence. In addition, we study and exploit the relationship of the knapsack problem to the 2-secretary problem. The generalized assignment problem (GAP) includes, besides the knapsack problem, several important problems related to scheduling and matching. We show that in the same online setting, applying the proposed sequential approach yields a (1/6.99)-competitive randomized algorithm for GAP. Again, our proposed algorithm outperforms the current best result of competitive ratio 1/8.06 (Kesselheim et al. in SIAM J Comput 47(5):1939–1964, 2018).


Introduction
Many real-world problems can be considered resource allocation problems. For example, consider the loading of a cargo plane with (potential) goods of different weights. Each item raises a certain profit for the airline if it is transported; however, not all goods can be loaded due to airplane weight restrictions. Clearly, the dispatcher seeks for a maximum profit packing fulfilling the capacity constraint. This example from [1] illustrates the knapsack problem: Given a set of n items, specified by a size and a profit value, and a resource (called knapsack) of fixed capacity, the goal is to find a subset of items (called packing) with maximum total profit and whose total size does not exceed the capacity. Besides being a fundamental and extensively studied problem in combinatorial optimization, knapsack problems arise in many and various practical settings. We refer the readers to textbooks [1,2] and to the surveys of previous work in [3,4] for further references.
The introductory example from cargo logistics can be generalized naturally to multiple airplanes of different capacities. Here, the size and the profit of an item may depend on the airplane and on the schedule, respectively. This leads to the generalized assignment problem (GAP) [2], where resources of different capacities are given, and the size and the profit of an item depend on the resource to which it is assigned. The GAP includes many prominent problems, such as the (multiple) knapsack problem [5], weighted bipartite matching [6], AdWords [7], and the display ads problem [8]. Further applications of GAP are outlined in the survey articles [9,10].
We study online variants of the knapsack problem and GAP. Here, n items are presented sequentially, and the decision for each item must be made immediately upon arrival. This setting would arise in our logistics example if the dispatcher needs to answer customer requests immediately without knowledge of future requests. In fact, many real-world optimization problems occur as online problems, as often decisions must be made under uncertain conditions. The online knapsack problem has been studied in particular in the context of online auctions [11,12].
Typically, the performance measure for online algorithms is the competitive ratio, which is defined as the ratio between the values of the algorithmic solution and an optimal offline solution for a worst-case input. The knapsack problem admits no randomized algorithm of bounded competitive ratio in the general online setting [12]. This holds even if only a single item can be packed, as known from the secretary problem [13,14]. However, these hardness results are based on a worst-case input presented in adversarial order. In the random order model, the performance of an algorithm is evaluated for a worst-case input, but the adversary has no control over the input order; the input sequence is drawn uniformly at random among all permutations.
In order to define the competitive ratio of an algorithm A in this model formally, let A(I) and OPT(I) denote the profits of the solutions of A and an optimal offline algorithm, respectively, for input I . We say that A is r-competitive (or has competitive ratio r) in the random order model if holds for all inputs I . Here, the expectation is over the random permutation as well as over random choices of the algorithm. The o(1)-term is asymptotic with respect to the number n of items in the input. The random order model became increasingly popular in the field of online algorithms. An early and well-known example is the secretary problem [13,14]. Nowadays, the matroid secretary problem [15,16] is considered as one of the most central problems in this field. Further multiple-choice generalizations [17,18] are part of active research as well. The model has also been successfully applied to other problem classes including scheduling [19][20][21], packing [22][23][24][25][26], graph problems [27][28][29], facility location [30], budgeted allocation [31], and submodular welfare maximization [32].

Online Knapsack Problem
The online knapsack problem was first studied by Marchetti-Spaccamela and Vercellis [33], who showed that no deterministic online algorithm for this problem can obtain a constant competitive ratio. Moreover, Chakrabarty et al. [12] demonstrated that this fact cannot be overcome by randomization.
Given such hardness results, several relaxations have been introduced and investigated. Most relevant to our work are results in the random order model. Introduced as the secretary knapsack problem [34], Babaioff et al. developed a randomized algorithm of competitive ratio 1∕(10e) < 1∕27 . Kesselheim et al. [25] achieved a significant improvement by developing a (1/8.06)-competitive randomized algorithm for the generalized assignment problem. Finally, Vaze [35] showed that there exists a deterministic algorithm of competitive ratio 1∕(2e) < 1∕5. 44 , assuming that the maximum profit of a single item is small compared to the profit of the optimal solution.
Apart from the random order model, different further relaxations have been considered. Marchetti-Spaccamela and Vercellis [33] studied a stochastic model wherein item sizes and profits are drawn from a fixed distribution. Lueker [36] obtained improved bounds in this model. Chakrabarty et al. [12] studied the problem when the density (profit-size ratio) of each item is in a fixed range [L, U]. Under the further assumption that item sizes are small compared to the knapsack capacity, Chakrabarty et al. proposed an algorithm of competitive ratio ln(U∕L) + 1 and provided a lower bound of ln(U∕L) . Another branch of research considers removable models, where the algorithm can remove previously packed items. Removing such items can incur no cost [37,38] or a cancellation cost (buyback model, [39][40][41]). Recently, Vaze [42] considered the problem under a (weaker) expected capacity constraint. This variant admits a competitive ratio of 1/4e.

Online GAP
Since all hardness results for online knapsack also hold for online GAP, research focuses on stochastic variants or modified online settings. Currently, the only result for the random order model is the previously mentioned (1/8.06)-competitive randomized algorithm proposed by Kesselheim et al. [25]. To the best of our knowledge, the earliest paper considering online GAP is due to Feldman et al. [8]. They obtained an algorithm of competitive ratio tending to 1 − 1∕e in the free disposal model. In this model, the total size of items assigned to a resource might exceed its capacity; in addition, no item consumes more than a small fraction of any resource. A stochastic variant of online GAP was studied by Alaei et al. [43]. Here, the size of an item is drawn from an individual distribution that is revealed upon arrival of the item, together with its profit. However, the algorithm learns the actual item size only after the assignment. If no item consumes more than a (1/k)-fraction of any resource, the algorithm proposed by Alaei et al. has competitive ratio 1 − 1∕ √ k.

Online packing LPs
Packing problems where requests can consume d ≥ 1 different resources lead to general online packing LPs. Note that the special case of d = 1 is the generalized assignment problem. Buchbinder and Naor [44] initiated the study of online packing LPs in the adversarial model. The random order model admits (1 − )-competitive algorithms assuming large capacity ratios, i.e., the capacity of any resource is large compared to the maximum demand for it. This has been shown in a sequence of papers [22,23,25,26]. Recently, Kesselheim et al. [25] gave an algorithm of com- . For d = 1 , this result matches the lower bound by Kleinberg [18].

Our Contributions
As outlined above, for online knapsack and GAP in the adversarial input model, nearly all previous works attain constant competitive ratios at the cost of either (a) imposing structural constraints on the input or (b) significantly relaxing the original online model. Therefore, we study both problems in the random order model, which is less pessimistic than the adversarial model but still considers worst-case instances without further constraints on the item properties. For the knapsack problem, our main result is the following.
Theorem 1 There exists a (1/6.65)-competitive randomized algorithm for the online knapsack problem in the random order model.
One challenge in the design of knapsack algorithms is that the optimal packing can have, on a high level, at least two different structures. Either there are a few large items, constituting the majority of the packing's profit, or there are many small such items. Previous work [25,34] is based on splitting the input according to item sizes and then employing algorithms tailored for these restricted instances. However, the algorithms from [25,34] choose a single item type via an initial random choice, and then pack items of that type exclusively. In contrast, our approach considers different item types in distinct time intervals, rather than discarding items of a specific type in 1 3 advance. More precisely, we develop algorithms A L and A S which are combined in a novel sequential approach: While large items appearing in early rounds are packed using A L , algorithm A S is applied to pack small items revealed in later rounds. We think that this approach may be helpful for other problems in similar online settings as well.
The proposed algorithm A L deals with the knapsack problem where all items consume more than 1/3 of the capacity (we call this problem 2-KS). The 2-KS problem is closely related to the k-secretary problem [18] for k = 2 . We also develop a general framework that allows to employ any algorithm for the 2-secretary problem to obtain an algorithm for 2-KS. As a side product, we obtain a simple (1/3.08)-competitive deterministic algorithm for 2-KS in the random order model. For items whose size is at most 1/3 of the resource capacity, we give a simple and efficient algorithm A S . Here, a challenging constraint is that A L and A S share the same resource, so we need to argue carefully that the decisions of A S are feasible, given the packing of A L from previous rounds.
Finally, we show that the proposed sequential approach also improves the current best result for GAP [25] from competitive ratio 1/8.06 to 1/6.99.

Theorem 2
There exists a (1/6.99)-competitive randomized algorithm for the online generalized assignment problem in the random order model.
For this problem, we use the algorithmic building blocks A L , A S developed in [25,28]. However, we need to verify that A L , an algorithm for edge-weighted bipartite matching [28], satisfies the desired properties for the sequential approach. We point out that the assignments of our algorithm differ structurally from the assignments of the algorithm proposed in [25]. In the assignments of the latter algorithm, all items are either large or small compared to the capacity of the assigned resource. In our approach, both situations can occur, because resources are managed independently.

Roadmap
We focus on the result on the knapsack problem (Theorem 1) in the first sections of this paper. For this purpose, we provide elementary definitions and facts in Sect. 2. Our main technical contribution is formally introduced in Sect. 3: Here, we describe an algorithmic framework performing two algorithms A L , A S sequentially. In Sects. 4 and 5, we design and analyze the algorithms A L and A S for the knapsack problem. Finally, in Sect. 6 we describe how the sequential approach can be applied to GAP.

Knapsack Problem
We are given a set of items I = [n] , each item i ∈ I has size s i ∈ ℚ >0 and a profit (value) v i ∈ ℚ ≥0 . The goal is to find a maximum profit packing into a knapsack of size W ∈ ℚ >0 , i.e., a subset M ⊆ I such that ∑ i∈M s i ≤ W and ∑ i∈M v i is maximized. W.l.o.g. we can assume s i ≤ W for all i ∈ I . In the online variant of the problem, a single item i is revealed together with its size and profit in each round ∈ [n] . The online algorithm must decide immediately and irrevocably whether to pack i. We call an item visible in round if it arrived in round or earlier.
We classify items as large or small, depending on their size compared to W and a parameter ∈ (0, 1) to be determined later.

Definition 1
We say an item i is -large if s i > W and -small if s i ≤ W . Whenever is clear from the context, we say an item is large or small for short. Based on the given item set I, we define two modified item sets I L and I S , which are obtained as follows: • I L : Replace each small item by a large item of profit 0 • I S : Replace each large item by a small item of profit 0.
Therefore, I L only contains large items and I S only contains small items. We can assume that no algorithm packs a zero-profit item, thus any algorithmic packing of I L or I S can be turned into a packing of I having the same profit. Let OPT , OPT L , and OPT S be the total profits of optimal packings for I, I L , and I S , respectively. A useful upper bound for OPT is

Bounding Sums by Integrals
In order to obtain lower or upper bounds on sums in closed form, we often make use of the following facts.
Fact 1A Let f be a non-negative real-valued function and let a, b ∈ ℕ . If f is monotonically decreasing, then ∫ b+1 a (1) OPT ≤ OPT L + OPT S .

Sequential Approach
A common approach in the design of algorithms for secretary problems is to set two phases: a sampling phase, where all items are rejected, followed by a decision phase, where some items are accepted according to a decision rule. Typically, this rule is based on the information gathered in the sampling phase. We take this concept a step further: The key idea of our sequential approach is to use a part of the sampling phase of one algorithm as decision phase of another algorithm, which itself can have a sampling phase. This way, two algorithms are performed in a sequential way, which makes better use of the entire instance. We combine this idea with using different strategies for small and large items.
Formally, let A L and A S be two online knapsack algorithms and I L and I S be the item sets constructed according to Definition 1. Further, let 0 < c < d < 1 be two parameters to be specified later. Our proposed algorithm samples the first cn rounds; no item is packed during this time. From round cn + 1 to dn, the algorithm considers large items exclusively. In this interval it follows the decisions of A L . After round dn, the algorithm processes only small items and follows the decisions of A S . However, it might be the case that an item accepted by A S cannot be packed because the knapsack capacity is exhausted due to the packing of A L in earlier rounds. Note that all rounds 1, … , dn can be considered as the sampling phase for A S . A formal description is given in Algorithm 1. Here, for a given input sequence of I, let L and S denote the corresponding sequences from I L and I S , respectively. Note that is revealed sequentially and L , S can be constructed online. For any input sequence , let ( ) denote the item at position ∈ [n].
In the final algorithm, we set the threshold for small items to = 1∕3 and use Algorithm 1 with parameters c = 0.42291 and d = 0.64570 . The choice of c and d maximizes the minimum of A L ∕OPT L and A S ∕OPT S . For simplicity, we assume cn, dn ∈ ℕ . If n is large enough, this assumption does not affect the competitive ratio substantially. We next give a high-level description of the proof of Theorem 1.

Proof (of Theorem 1) Let
A be Algorithm 1 and let A L , A S be the algorithms developed in Sect. 4 and 5. In the next sections, we prove the following results for r = 1∕6.65 − o(1) (see Lemmas 6 and 11): The expected profit from A L in rounds cn + 1, … , dn is at least r ⋅ OPT L , and the expected profit from A S in rounds dn + 1, … , n is at least r ⋅ OPT S . Together with inequality (1), we obtain ◻ The order in which A L and A S are arranged in Algorithm 1 follows from two observations. Algorithm A S is powerful if it samples roughly 2n/3 rounds; a part of this long sampling phase can be used as the decision phase of A L , for which a shorter sampling phase is sufficient. Moreover, the first algorithm should either pack high-profit items, or should leave the knapsack empty for the following algorithm with high probability. The algorithm A L we propose in Sect. 4 has this property (see Lemma 7), in contrast to A S . If A S would precede A L , the knapsack would be empty after round dn with very small probability, in which case we would not benefit from A L at all.
Finally, note that stronger algorithms for the respective sub-problems can be obtained by choosing different parameters or algorithmic approaches (see Lemma 5 and [25]). However, we seek for maximizing the competitive ratio of Algorithm 1 and therefore need algorithms A L and A S that perform well within the sequential framework.

Large Items
The approach presented in this section is based on the connection between the online knapsack problem under random arrival order and the k-secretary problem [18]. In the latter problem, the algorithm can accept up to k items and the goal is to maximize the sum of their profits. Therefore, we assume that a k-secretary algorithm can observe the actual profits of the items, as opposed to the ordinal version of the problem, where an algorithm can only decide based on relative merits. This way, the k-secretary problem generalizes the classical secretary problem [13,14] and is itself a special case of the online knapsack problem under random arrival order (if all knapsack items have size W/k). In our setting, each large item consumes more than = 1∕3 of the knapsack capacity. We call this problem 2-KS, since at most two items can be packed completely. Therefore, any 2-secretary algorithm can be employed to identify two highprofit items for the knapsack packing. However, after packing the first item, the resource might be exhausted, such that the second item identified by the 2-secretary algorithm cannot be packed.
Although this idea can be generalized to any k-secretary algorithm and corresponding -large items, the approach seems stronger for small k: While 1-KS is exactly 1-secretary, the characteristics of k-KS and k-secretary deviate with growing k. Our results show that the problems 2-secretary and 2-knapsack are still close enough to benefit from such an approach.
In the following, let A L be Algorithm 2. This is an adaptation of the algorithm single-ref developed for the k-secretary problem in [45]. As discussed above, 2-secretary and 2-KS are similar, but different problems. Therefore, in our setting it is not possible to apply the existing analysis from [45] or from any other k-secretary algorithm directly. We further note that in the approach described below, in principle any 2-secretary algorithm can be employed. In Sect. 4.4, we discuss several alternative algorithms.
Assumption. For this section, we assume that all profits are distinct. This is without loss of generality, as ties can be broken by adjusting the profits slightly, using the items' identifiers. Further, we assume v 1 > v 2 > … > v n and say that i is the rank of item i.

Packing Types
As outlined above, in contrast to the 2-secretary problem, not all combinations of two knapsack items can be packed completely. Therefore, we analyze the probability that A L selects a feasible set of items whose profit can be bounded from below. We restrict our analysis to packings where an item i ∈ {1, 2, 3, 4} is packed as the first item and group such packings into several packing types A-M defined in the following. Although covering more packings might lead to further insights into the problem and to a stronger result, we expect the improvement to be marginal.
Let p X be the probability that A L returns a packing of type X ∈ {A, … , M} . In addition, let p i for i ∈ [n] be the probability that A L packs i as the first item. Finally, let p ij for i, j ∈ [n] be the probability that A L packs i as the first item and j as the second item.
In a packing of type A, the items 1 and 2 are packed in any order. Therefore, p A = p 12 + p 21 . The types B and C are defined analogously using the items {1, 3} and {2, 3} , respectively. In a packing of type D, the item 1 is accepted as the first item, together with no or any second item j. This happens with probability p D = p 1 . Accordingly, we define types E, F, and G using the items 2, 3, and 4, respectively. Finally, for each item i ∈ {1, 2, 3} , we introduce two further packing types. For i = 1 , types H and I cover packings where the first accepted item is 1, the second accepted item j is not 2 (type H) and not 3 (type I), respectively. Therefore, we get p H = p 1 − p 12 and p I = p 1 − p 13 . Packing types J-K and L-M describe analogous packings for i = 2 and i = 3 , respectively. Table 1 shows all packing types A-M and their probabilities expressed by p i and p ij .
In Sect. 4.3, we use the packing types to describe a subset of packings whose profit can be bounded against OPT L . For example, suppose that Then, all relevant packings are of type A, H, or J. As these types are disjoint by definition, we immediately obtain

Acceptance Probabilities of Algorithm 2
In the following, we compute the probabilities p i and p ij from Table 1 as functions of c and d. Throughout the following proofs, we denote the position of an item i in a given permutation with pos (i) ∈ [n] . Further, let a be the maximum profit item from the sampling.
We think of the random permutation as being sequentially constructed. The fact given below follows from the hypergeometric distribution and becomes helpful in the proofs of Lemmas 1 and 2. Table 1 Definition of packing types A-M. We use set notation {i, j} if i and j can be packed in any order, and tuple notation (i, j) if the packing order must be as given In the first lemma, we provide the exact probability p i for all i ∈ [n] and give lower bounds for p i when i ∈ [4].

Lemma 1 The probability that item i ∈ [n] is accepted as the first item is
Moreover, we have the lower bound Proof In the first part of this proof, we analyze the probability that item i is accepted as the first item at a fixed position k ≥ cn + 1 . As a is defined as the best sampling item, pos (a) ≤ cn must hold. A permutation uniformly drawn at random satisfies pos (i) = k and pos (a) ≤ cn with probability 1 Next, we draw the remaining k − 2 items for the positions before k (see Fig. 1). Since i is packed as the first item, all previous items (except for a) must have rank greater than a. As these items are drawn from the remaining n − 2 items (of which n − a have rank greater than a), the probability for this step is h(n − 2, n − a, k − 2) according to Fact 1. Using the law of total probability for k ∈ {cn + 1, … , dn} and a ∈ {i + 1, … , n} , we obtain Here, the last identity In the second part of the proof, we derive a lower bound for p i . We first consider the quotient of binomial coefficients from Eq. (2) and observe Combining Equation (2) and inequality (3) yields Now, the goal is to find a closed expression which bounds the last sum in inequality (4) from below. We have The claim follows by substituting F(dn) − F(cn) in inequality (7) by the corresponding expression from the table and noting that (i + 1) (1) . ◻ Next, we analyze the probabilities p ij with i < j and give lower bounds for p 12 , p 13 , and p 23 .

Lemma 2 Let i and j be two items with i < j . The probability that i is selected as the first item and j is selected as the second item is
Moreover, it holds that Pos.

Fig. 2
Input sequence considered in Lemma 2. The gray dashed slots represent items of rank greater than a Proof Let i, j be two items with i < j . The proof follows the same structure as the proof of Lemma 1. Again, we construct the permutation by drawing the positions for items i, j, and a first and afterwards all remaining items with position up to pos (j) (see Fig. 2). Fix positions k = pos (i) and l = pos (j) . Again, pos (a) ≤ cn must hold by definition of a. The probability that a random permutation satisfies these three position constraints is ∶= 1 All remaining items up to position l must have rank greater than a. Thus, we need to draw l − 3 items from a set of n − 3 remaining items, from which n − a have rank greater than a. This happens with probability h(n − 3, n − a, l − 3) . Using the law of total probability for k, l with cn + 1 ≤ k < l ≤ dn and a ∈ {j + 1, … , n} , we obtain Again, by observing , we obtain finally To prove the second part of the lemma, first note that Equation (8) does not depend on i, thus we have p 13 = p 23 . It remains to find lower bounds for p 12 and p 23 . We start with p 12 . By Equation (8) Similarly, using Fact 1A, we obtain and By combining inequalities (9) to (12), we obtain Since c n ⋅ 1 − cn−1 dn−1 = o(1) , this gives the claim for p 12 . Next, we find a lower bound for p 23 . Equation (8) with j = 3 gives By splitting this expression into two parts we obtain where the inequality follows from inequality (9). Hence, using the lower bound for p 12 , the claim for p 23 follows if we can show (1) . Since l l−2 decreases monotonically in l, Fact 1A implies , it follows further We observe that by Fact 1B. This implies 2 = o(1) and concludes the proof. ◻ The remaining probabilities p 21 and p 32 can be obtained from the symmetry property stated in the next lemma.

Lemma 3 For any two items i and j it holds that p ij = p ji .
Proof Suppose i is accepted first and j is accepted as the second item in the input sequence . Consider the sequence ′ obtained from by swapping i with j. Since j and i are the first two elements beating the best sampling item in ′ , Algorithm 2 will select j and i on input ′ . Hence, the number of permutations must be the same for both events, which implies the claim. ◻ Therefore, we can obtain all probabilities from Table 1 using Lemmas 1, 2, and 3.

Analysis
Let T be the set of items in the optimal packing of I L . This set may contain a single item, may be a two-item subset of {1, 2, 3} , or may be a two-item subset containing an item j ≥ 4 . In the following, we analyze the performance of Algorithm 2 for each case.

Single-item Case
If the optimal packing contains a single item, it is the most profitable item. Let case 1 be this case. Here, we have T = {1} and A L ≥ p D OPT L .

Two-item Cases
In cases 2-4, we consider packings of the form T = {i, j} with 1 ≤ i < j ≤ 3 . We define cases 2, 3, and 4 as T = {1, 2} , T = {1, 3} , and T = {2, 3} , respectively. We want to consider all algorithmic packings whose profit can be bounded in terms of OPT L = v i + v j . For this purpose, for each case 2-4 we build three groups of feasible packing types, according to whether the profit of a packing is OPT L , at least v i , or in the interval [v j , v i ) . We ensure that no packing is counted multiple times by (a) choosing appropriate packing types and (b) grouping these packing types in a disjoint way, according to their profit. Let w be the probability that the algorithm returns the optimal packing in case w ∈ {2, 3, 4} . It holds that 2 = p A , 3 = p B , and 4 = p C . In addition, let w be the probability that an item k ≤ i is packed as the first item in case w ∈ {2, 3, 4} . We have 2 = p H , 3 = p I , and 4 = p D + p K . Finally, let w be the probability that an item k with i < k ≤ j is packed as the first item in case w ∈ {2, 3, 4} . It holds that 2 = p J , 3 = p E + p L , and 4 = p M .
Finally, we define case 5 as T = {i, j} with i ≥ 1 , j ≥ 4 , and i < j . In this case, note that packings of type D contain an item of value at least v i , and packings of type E, F, and G contain an item of value at least v j . Hence, we can slightly abuse the notation and set 5 = 0 , 5 = p D , and 5 = p E + p F + p G , such that it holds that To bound this term against OPT L = v i + v j , consider the following two cases: If w ≥ w , we obtain from Chebyshev's sum inequality 1 If w < w , we trivially have w v i + w v j > w (v i + v j ).

Competitive Ratio
The competitive ratio of A L is the minimum over all cases 1-5. Hence, setting 1 = p D and 1 = 1 = 0 , we obtain Clearly, inequality (15) simplifies depending on w ≥ w or w < w . The following lemma gives a sufficient condition for w ≥ w .
1 Let a 1 ≥ a 2 ≥ … ≥ a n and b

Proof
We first show that f (c) ≥ f (d) is equivalent to 5 ≥ 5 . Note that 5 = p D = p 1 and 5 = p E + p F + p G = p 2 + p 3 + p 4 . Now, using Lemma 1 and ignoring lower order terms, we have Therefore, the claim for w = 5 holds by assumption. For 2 ≤ w ≤ 4 , the claims follow immediately from f (c) ≥ f (d) and the symmetry property of Lemma 3: ◻ We obtain the following two lemmas. If A L uses the entire input sequence ( d = 1 ), this algorithm is (1/3.08)-competitive.

Lemma 5 With c = 0.23053 and d = 1 as parameters, we have
Note that 2-KS includes the secretary problem (case 1); thus, no algorithm for 2-KS can have a better competitive ratio than 1∕e < 1∕2.71 . In the final algorithm we set d < 1 to benefit from A S . The next lemma has already been used to prove Theorem 1 in Sect. 3.

Lemma 6
With c = 0.42291 and d = 0.64570 as parameters, we have Recall that in Algorithm 1, we can only benefit from A S if A L has not filled the knapsack completely. Thus, the following property is crucial in the final analysis.

Lemma 7 With a probability of at least c/d, no item is packed by A L .
Proof Fix any set of dn items arriving in rounds 1, … , dn . The most profitable item v * from this set arrives in the sampling phase with probability c/d. If this event occurs, no item in rounds cn + 1, … , dn beats v * and A L will not select any item. ◻

Discussion of other 2-Secretary Algorithms
As mentioned in the introduction of Sect. 4, the approach and its analysis of this section are general enough to cover all two-choice secretary algorithms. Therefore, a natural question to ask is which algorithm is a good choice within this framework. Algorithm 2 is based on the algorithm single-ref developed for the k-secretary problem in [45]. In the following, we discuss several algorithms for 2-secretary and related problems. The optimistic algorithm by Babaioff et al. [34] was developed for the k-secretary problem and performs slightly better than single-ref in the case k = 2 ; the competitive ratios of both algorithms are 0.4168 and 0.4119, respectively [45]. However, optimistic has a weaker threshold for accepting the first item than single-ref, thus the probability considered in Lemma 7 would fall below c/d. In the present analysis of the sequential approach, we can only benefit from the second algorithm A S if A S starts with an empty knapsack (we will use this property later in Lemma 11). Hence, it is not clear if the slight gain in the expected profit compensates the drawback of an early resource consumption.
A strong algorithm for the 2-secretary problem has been developed by Chan et al. [17]. The algorithm is based on a sophisticated set of decision rules, leading to a competitive ratio of 0.49. Again, the probability considered in Lemma 7 would be smaller for this algorithm. Moreover, it seems overly elaborate to find equivalents of Lemmas 1, 2, 4, and 7.
Another candidate algorithm is due to Nikolaev [46] and Tamaki [47] who proposed an algorithm for a slightly different secretary problem: Here, the objective is to maximize the probability of selecting the best two items. This algorithm depends on two parameters 0 ≤ c 1 ≤ c 2 ≤ 1 . The first item is selected just as in single-ref with sampling size c 1 n (select the first item beating the best sampling item). The second item must beat the first item if it arrives before round c 2 n , or (merely) the best sampling item if it arrives later than this round. The success probability tends asymptotically to 0.2254 with c 1 = 0.2291 and c 2 = 0.6065 , which is best possible [47]. If we use this algorithm within our framework, it turns out that the best competitive ratio is achieved for c 1 = c 2 . However, for c 1 = c 2 , this algorithm is equal to single-ref in the case k = 2.
Therefore, we conclude that even though various algorithms for the 2-secretary problem stronger than single-ref exist, it is not clear if they can improve the performance of the overall algorithm within the sequential framework. On the other side, Algorithm 2 (based on single-ref) is fairly easy to analyze and selects high-profit items with sufficient high probability.

Small Items
For (1/3)-small items, we use solutions for the fractional problem variant and obtain an integral packing via randomized rounding. This approach has been applied successfully to packing LPs [25]; however, for the knapsack problem it is not required to solve LP relaxations in each round (as in [25]). Instead, here, we use solutions of a greedy algorithm, which is well-known to be optimal for the fractional knapsack problem. Particularly, this algorithm is both efficient in running time and easy to analyze. We next formalize the greedy solution for any set T of items. Let the density of an item be the ratio of its profit to its size. Consider any list L containing the items from T ordered by non-increasing density. We define the rank (i) of item i as its position in L and (l) as the item at position l in L. Thus, (l) = −1 (l) denotes the l-th densest item. Let k be such that The fraction of item i in the greedy solution is now defined as i.e., the k − 1 densest items are packed integrally and the remaining space is filled by the maximum feasible fraction of the k-th densest item. Let OPT(T) and OPT * (T) denote the profits of optimal integral and fractional packings of T, respectively. It is easy to see that satisfies

Algorithm
The algorithm A S for (1/3)-small items, which is formally defined in Algorithm 3, works as follows. During the initial sampling phase of dn rounds, the algorithm rejects all items. In each round ≥ dn + 1 , the algorithm computes a greedy solution x ( ) for I S ( ) . Here, I S ( ) denotes the subset of I S revealed up to round . The algorithm packs the current online item i with probability x ( ) i . However, generally, this can only be done if the remaining capacity of the knapsack is at least Note that in case of an integral coefficient x ( ) i ∈ {0, 1} , the packing step is completely deterministic. Moreover, in any greedy solution x ( ) , there is at most one item i with fractional coefficient x ( ) i ∈ (0, 1) . Therefore, in expectation, there is only a small number of rounds where the algorithm actually requests randomness. Although this is not relevant for the proof of the competitive ratio, we provide a short proof of this observation in the following.
Observation 1 Let X denote the number of rounds where Algorithm 3 packs an item with probability x i ∈ (0, 1) . It holds that [X] ≤ ln(1∕d) ≤ 0.44.
Proof Consider any round and let x ( ) be the greedy knapsack solution computed by Algorithm 3. By definition of x ( ) , at most one of the visible items has a fractional coefficient x ( ) i ∈ (0, 1) . The probability that this item i arrives in round is 1∕ in a random permutation. Let X be an indicator variable for the event that Algorithm 3 packs an item at random in round . By the above argument, we have Since Algorithm 3 selects items starting in round dn + 1 , we obtain ◻ Note that Algorithm 2 and the sequential approach (Algorithm 1) are deterministic algorithms. Therefore, our overall algorithm requests randomness in expectation in less than one round.

Analysis
Before we analyze the competitive ratio of A S in a sequence of lemmas, we make a few technical observations and introduce further notation.
In round dn + 1 , the knapsack might already have been filled by A L with large items from previous rounds. For now, we assume an empty knapsack after round dn and denote this event by . In the final analysis, we will use the fact that [ ] can be bounded from below, which is according to Lemma 7.
The description of Algorithm 3 is tailored to (1/3)-small items, in order to complement Algorithm 2. Anyway, it is straightforward to generalize this algorithm to arbitrary maximum item size . In order to show similarities with the analysis from Sect. 6 later, we state the following lemmas with as a parameter. For this purpose, we define = 1 1− (and obtain = 3∕2 in the final analysis). Finally, let be a greedy (offline) solution for I S . By the following lemma, the probability that an item i ∈ I S is packed by A S is proportional to i . By treating i as a parameter in the next two lemmas, it is not required to analyze the profit in each round in expectation over all items. The latter approach appears in related work [28], where stochastic dependencies need to be handled carefully.

Lemma 8 Let i ∈ I S and E i ( ) be the event that the item i is packed by
Proof In a random permutation, item i arrives in round with probability 1/n. In round ≥ dn + 1 , the algorithm decides to pack i with probability x ( ) i . Note that the rank of item i in I S ( ) is less than or equal to its rank in I S . According to the greedy solution's definition, this implies x ( ) i ≥ i . Finally, the -small item i can be packed successfully if the current resource consumption X is at most (1 − )W . In the following, we investigate the expectation of X to give a probability bound using Markov's inequality at the end of this proof.
Let X k be the resource consumption in round k < . By assumption, the knapsack is empty after round dn, thus X = ∑ −1 k=dn+1 X k . Let Q be the set of k visible items in round k. The set Q can be seen as uniformly drawn from all k-item subsets and any item j ∈ Q is the current online item of round k with probability 1/k. The algorithm packs any item j with probability x (k) j , thus where the last inequality holds because x (k) is a feasible solution for a knapsack of size W. By the linearity of expectation and the previous inequality, the expected resource consumption up to round is Using Markov's inequality, we obtain which concludes the proof. ◻ Using Lemma 8 we easily obtain the total probability that a specific item will be packed.

Lemma 9 Let i ∈ I S and E i be the event that the item i is packed by A S . It holds that
Proof Summing the probabilities from Lemma 8 over all rounds ≥ dn + 1 gives By Fact 1B, we obtain and resolving the integral yields The claim follows by combining inequalities (16) and (17) and by rearranging terms. ◻ The following lemma bounds the expected profit of the packing of A S , assuming the event .

Lemma 10 We have
By Lemma 9, the probability that an item i is packed, assuming , is The conditioning on can be resolved using Lemma 7. We obtain the following lemma, which is the second pillar in the proof of Theorem 1 and concludes this section.

Extension to GAP
In this section, we show that the sequential approach introduced in Sect. 3 can be easily adapted to GAP, yielding a (1/6.99)-competitive randomized algorithm. We first define the problem formally. GAP. We are given a set of items I = [n] and a set of resources R = [m] of capacities W r ∈ ℚ >0 for r ∈ R . If item i ∈ I is assigned to resource r ∈ R , this raises profit (value) v i,r ∈ ℚ ≥0 , but consumes s i,r ∈ ℚ >0 of the resource's capacity. The goal is to assign each item to at most one resource such that the total profit is maximized and no resource exceeds its capacity. We call the tuple (v i,r , s i,r ) an option of item i and w.l.o.g. assume that options for all resources exist. This can be ensured by introducing dummy options with v i,r = 0 . In the online version of the problem, in each round an item is revealed together with its set of options. The online algorithm must decide immediately and irrevocably, if the item is assigned. If so, it has to specify the resource according to one of its options.
Again, we construct restricted instances I L and I S according to the following definition, which generalizes Definition 1. Let ∈ (0, 1).

Definition 2
We call an option (v i,r , s i,r ) -large if s i,r > W r and -small if s i,r ≤ W r . Whenever is clear from the context, we say an option is large or small for short. Based on a given instance I for GAP, we define two modified instances I L and I S which are obtained from I as follows.
-I L : Replace each small option (v i,r , s i,r ) by the large option (0, W r ).
-I S : Replace each large option (v i,r , s i,r ) by the small option (0, W r ).
Thus, I L only contains large options and I S only contains small options. However, by construction no algorithm will assign an item according to a zero-profit option. We define OPT , OPT L , and OPT S accordingly. Note that the inequality OPT ≤ OPT L + OPT S holds also for GAP.
The sequential framework of Algorithm 1 can be adapted in a straightforward manner by replacing terms like packing with assignment to resource r. Here, we set the threshold parameter to = 1∕2 . In the following subsections, we specify algorithms A L and A S for (1/2)-large and (1/2)-small options, respectively.

Large Options
If each item consumes more than one half of a resource, no two items can be assigned to this resource. Thus, we obtain the following matching problem.
Edge-weighted bipartite matching. Given a bipartite graph G = (L ∪ R, E) and a weighting function w ∶ E → ℚ ≥0 , the goal is to find a bipartite matching M ⊆ E such that w(M) ∶= ∑ e∈M w(e) is maximal. In the online version, the (offline) nodes from R and the number n = |L| are known in advance, whereas the nodes from L are revealed online together with their incident edges. In the case of GAP, L is the set of items, R is the set of resources, and the weight of an edge e = {l, r} is w(e) = v l,r .
Kesselheim et al. [28] developed an optimal (1/e)-competitive algorithm for the online problem under random arrival order. Adapting this algorithm to the sequential approach with parameters c and d leads to the following algorithm A L : During the first cn rounds, no edge is added to the matching. Then, in each round , the algorithm computes a maximum edge-weighted matching M ( ) for the graph revealed up to this round. Let l ∈ L be the online vertex of round . If l is matched in M ( ) to some node r ∈ R , we call e ( ) = {l, r} the tentative edge of round . Now, if r is still unmatched and ≤ dn , the tentative edge is added to the matching.
A formal description of this algorithm is given in Algorithm 4. The proof of the approximation guarantee relies mainly on the following two lemmas; for completeness, we give the proofs from [28] here. The first lemma shows that the expected weight of any tentative edge can be bounded from below.
Proof We use the fact that the random sequence of visible items in round can be obtained from the following process: First, the set Q of visible items in round is drawn uniformly at random from all -element subsets of L. Then, the online vertex of round is drawn uniformly at random from Q. Note that these random experiments are independent. After the first step, the matching M ( ) is already fixed. Let M * = M (n) be a maximum weight (offline) matching and M * Q = {e = {l, r} ∈ M * | l ∈ Q} the matching M * projected to visible nodes. We have w(M ( ) ) ≥ w(M * Q ) , since M ( ) is an optimal and M * Q a feasible matching for the graph revealed in round . As described above, each vertex l ∈ L has probability ∕n to be in Q, thus For the second step, we observe that each vertex from Q has the same probability of 1∕ to arrive in round . Let M be the domain of the random variable M ( ) . We have Combining (19) and (18)  Proof In each round k, the vertex r can only be matched if it is incident to the tentative edge e (k) ∈ M (k) of this round, i.e., e (k) = {l, r} where l ∈ L is the online vertex of round k. As l can be seen as uniformly drawn among all k visible nodes (particularly, independent of the order of the previous k − 1 items), l has probability 1/k to arrive w(e ( ) ) = ∑ in round k. Consequently, r is not matched in round k with probability 1 − 1∕k . This argument applies to all rounds cn + 1, … , . Therefore, ◻ Using Lemmas 12 and 13, we can bound the competitive ratio of A L in the following lemma. Note that we obtain the optimal (1/e)-competitive algorithm from [28] for c = 1∕e and d = 1.

Small Options
For small options, we use the LP-based algorithm from [25,Sec. 3.3] and analyze it within our algorithmic framework. In order to make this paper self-contained, we give a linear program for fractional GAP (LP 1), the algorithm, and its corresponding proofs.
After a sampling phase of dn rounds, in each round , the algorithm computes an optimal solution x ( ) of LP 1 for I S ( ) . Here, I S ( ) denotes the instance of small options revealed so far. Now, the decision to which resource the current online item i is assigned, if at all, is made at random using x ( ) : Resource r ∈ R is chosen with probability x ( ) i,r and the item stays unassigned with probability 1 − ∑ r∈R x ( ) i,r . Note that the item can only be assigned to the chosen resource if its remaining capacity is at least (1∕2) ⋅ W r .
To analyze Algorithm 5, we consider the gain of profit in round ≥ dn + 1 , denoted by A . For this purpose, let i ( ) be the item of that round and r ( ) the resource chosen by the algorithm. Now, it holds that A = v i ( ) ,r ( ) ⋅ i ( ) can be assigned to r ( ) , where in the first term, the expectation is over the item arriving in round and the resource chosen by the algorithm. The latter term only depends on the resource consumption of r ( ) in earlier rounds. In the next two lemmas, we give lower bounds for both terms. As in the proofs of Sect. 6.1, it is helpful to construct the random permutation of the first items in two independent steps: First, the set of visible items is drawn uniformly, without determining the order of items. Second, the online item arriving in round is drawn uniformly from this set.

Proof
The proof is similar to the proof of Lemma 12. As we consider a fixed round , we write i and r instead of i ( ) and r ( ) for ease of presentation. Further, we write v( ) ∶= ∑ j∈I S ∑ s∈R j,s v j,s for the profit of a fractional assignment . First, the set of visible items Q in round is drawn uniformly at random among all subsets of items. Let x (n) be an optimal (offline) solution to LP 1 and let x (n) | Q denote the restriction of x (n) to the items in Q, i.e., (x (n) | Q ) j,s = x (n) j,s if j ∈ Q and (x (n) | Q ) j,s = 0 if j ∉ Q . Since x (n) | Q is a feasible and x ( ) is an optimal solution for Q, we have v(x ( ) ) ≥ v(x (n) | Q ) .
As each item has the same probability of ∕n to be in Q, it holds that In the second step, the online item of round is determined by choosing one item from Q uniformly at random. Let X be the domain of x ( ) and x � ∈ X . We have where we used that each item from Q arrives in round with probability 1∕ and the algorithm assigns item j to resource s with probability x ′ j,s , given x ( ) = x � . By the law of total expectation, it follows that v i,r = 1 v(x ( ) ) . Combining with (20) gives the claim. ◻ Hence, by the previous lemma, the expected gain of profit in each round is at least a (1/n)-fraction of OPT S , supposing the remaining resource capacity is large enough. The probability for the latter event is considered in the following lemma. Here, a crucial property is that we deal with -small options. As in Sect. 5.2, we define = 1 1− .

Lemma 16
For any round ≥ dn + 1 , it holds that Proof Let be the event that no item is assigned to r after round dn. Note that does not necessarily hold, since A L might already have assigned items to r in earlier rounds. By Lemma 13, [ ] ≥ c d . Therefore, it is sufficient to show i ( ) can be assigned to r ( ) | ≥ 1 − ln dn . For this purpose, assume that holds and let X denote the resource consumption of r after round − 1 . Further, let X k be the resource consumption of r in round k < . We have X = ∑ −1 k=dn+1 X k . Let Q be the set of k visible items in round k. The set Q can be seen as uniformly drawn from all k-item subsets and any item j ∈ Q is the current online item of round k with probability 1/k. Now, the algorithm assigns any item j to resource r with probability x (k) j,r , thus where the last inequality follows from the capacity constraint for resource r in LP 1. By linearity of expectation and inequality (22), the expected resource consumption up to round is thus (20) v

3
Note that we obtain the same competitive ratio as in Lemma 11. ◻

Remark
The setting of large capacities (compared to the respective resource demands) has been addressed in several papers [8,12,43]. For instance, such settings arise in online auctions, where the budgets are very high compared to single bids. Although the algorithm A S is not tailored for this setting, a corresponding bound can be obtained easily from Lemma 17. Setting c = d clearly maximizes the performance of A S with respect to OPT S , thus the factor c/d vanishes. Assuming that the maximum resource demand is → 0 , the competitive ratio of A S tends to 2(1 − d) − ln 1 d , since → 1 . This function is maximized for d = 1∕2 , yielding a competitive ratio of 1 − ln(2) ≥ 0.3068.

Proof of Theorem 2
Finally, we prove our main theorem for GAP.

Proof (of Theorem 2)
We set the threshold between large and small options to = 1∕2 and consider Algorithm 1 with the algorithms A L and A S as defined previously. By Lemma 14, the expected gain of profit in rounds cn + 1, … , dn is