Streaming Algorithms for Bin Packing and Vector Scheduling
Problems involving the efficient arrangement of simple objects, as captured by bin packing and makespan scheduling, are fundamental tasks in combinatorial optimization. These are well understood in the traditional online and offline cases, but have been less well-studied when the volume of the input is truly massive, and cannot even be read into memory. This is captured by the streaming model of computation, where the aim is to approximate the cost of the solution in one pass over the data, using small space. As a result, streaming algorithms produce concise input summaries that approximately preserve the optimum value.
We design the first efficient streaming algorithms for these fundamental problems in combinatorial optimization. For Bin Packing, we provide a streaming asymptotic -approximation with memory, where hides logarithmic factors. Moreover, such a space bound is essentially optimal. Our algorithm implies a streaming -approximation for Vector Bin Packing in dimensions, running in space . For the related Vector Scheduling problem, we show how to construct an input summary in space that preserves the optimum value up to a factor of , where is the number of identical machines.
The streaming model captures many scenarios when we must process very large volumes of data, which cannot fit into the working memory. The algorithm makes one or more passes over the data with a limited memory, but does not have random access to the data. Thus, it needs to extract a concise summary of the huge input, which can be used to approximately answer the problem under consideration. The main aim is to provide a good trade-off between the space used for processing the input stream (and hence, the summary size) and the accuracy of the (best possible) answer computed from the summary. Other relevant parameters are the time and space needed to make the estimate, and the number of passes, which ideally should be equal to one.
While there have been many effective streaming algorithms designed for a range of problems in statistics, optimization, and graph algorithms (see surveys by Muthukrishnan  and McGregor ), there has been little attention paid to the core problems of packing and scheduling. These are fundamental abstractions, which form the basis of many generalizations and extensions [14, 13]. In this work, we present the first efficient algorithms for packing and scheduling that work in the streaming model.
A first conceptual challenge is to resolve what form of answer is desirable in this setting. If items in the input are too many to store, then it is also unfeasible to require a streaming algorithm to provide an explicit description of how each item is to be handled. Rather, our objective is for the algorithm to provide the cost of the solution, in the form of the number of bins or the duration of the schedule. Moreover, many of our algorithms can provide a concise description of the solution, which describes in outline how the jobs are treated in the design.
A second issue is that the problems we consider, even in their simplest form, are NP-hard. The additional constraints of streaming computation do not erase the computational challenge. In some cases, our algorithms proceed by adopting and extending known polynomial-time approximation schemes for the offline versions of the problems, while in other cases, we come up with new approaches. The streaming model effectively emphasizes the question of how compactly can the input be summarized to allow subsequent approximation of the problem of interest. Our main results show that in fact the inputs for many of our problems of interest can be “compressed” to very small intermediate descriptions which suffice to extract near-optimal solutions for the original input. This implies that they can be solved in scenarios which are storage or communication constrained.
We proceed by formalizing the streaming model, after which we summarize our results. We continue by presenting related work, and contrast with the online setting.
1.1 Problems and Streaming Model
The Bin Packing problem is defined as follows: The input consists of items with sizes (each between 0 and 1), which need to be packed into bins of unit capacity. That is, we seek a partition of the set of items into subsets , called bins, such that for any bin , it holds that . The goal is to minimize the number of bins used.
We also consider the natural generalization to Vector Bin Packing, where the input consists of -dimensional vectors, with the value of each coordinate between 0 and 1 (i.e., the scalar items are replaced with vectors ). The vectors need to be packed into -dimensional bins with unit capacity in each dimension, we thus require that (where, the infinity norm ).
The Makespan Scheduling problem is closely related to Bin Packing but, instead of filling bins with bounded capacity, we try to balance the loads assigned to a fixed number of bins. Now we refer to the input as comprising a set of jobs, with each job defined by its processing time . Our goal is to assign each job on one of identical machines to minimize the makespan, which is the maximum load over all machines.
In Vector Scheduling, a job is described not only by its processing time, but also by, say, memory or bandwidth requirements. The input is thus a set of jobs, each job characterized by a vector . The goal is to assign each job into one of identical machines such that the maximum load over all machines and dimensions is minimized.
In the streaming scenario, the algorithm receives the input as a sequence of items, called the input stream. We do not assume that the stream is ordered in any particular way (e.g., randomly or by item sizes), so our algorithms must work for arbitrarily ordered streams. The items arrive one by one and upon receiving each item, the algorithm updates its memory state. A streaming algorithm is required to use space sublinear in the length of the stream, ideally just , while it processes the stream. After the last item arrives, the algorithm computes its estimate of the optimal value, and the space or time used during this final computation is not restricted.
For many natural optimization problems outputting some explicit solution of the problem is not possible owing to the memory restriction (as the algorithm can store only a small subset of items). Thus the goal is to find a good approximation of the value of an offline optimal solution. Since our model does not assume that item sizes are integers, we express the space complexity not in bits, but in words (or memory cells), where each word can store any number from the input; a linear combination of numbers from the input; or any integer with bits (for counters, pointers, etc.).
1.2 Our Results
In Section 3, we present a streaming algorithm for Bin Packing, which outputs an asymptotic -approximation of OPT, the optimal number of bins, using memory. This means that the algorithm uses at most bins, and in our case, the additive term is bounded by the space used. The novelty of our contribution is to combine a data structure that approximately tracks all quantiles in a numeric stream  with techniques for approximation schemes [18, 33]. We show that we can improve upon the factor in the space complexity if randomization is allowed or if item sizes are drawn from a bounded-size set of real numbers. On the other hand, we argue that our result is close to optimal, up to a factor of , if item sizes are accessed only by comparisons (including comparisons with some fixed constants). Thus, one cannot get an estimate with at most bins by a streaming algorithm, unlike in the offline setting . The hardness emerges from the space complexity of the quantiles problem in the streaming model.
For Makespan Scheduling, one can obtain a straightforward streaming -approximation111Unlike for Bin Packing, an additive constant or even an additive term does not help in the definition of the approximation ratio, since we can scale every number on input by any and OPT scales by as well. with space of only by rounding sizes of suitably large jobs to powers of and counting the total size of small jobs. In a higher dimension, it is also possible to get a streaming -approximation, by the rounding introduced by Bansal et al. . However, the memory required for this algorithm is exponential in , precisely of size , and thus only practical when is a very small constant. Moreover, such a huge amount of memory is needed even if the number of machines (and hence, of big jobs) is small as the algorithm rounds small jobs into exponentially many types. See Section 4.2 for more details.
In case and make this feasible, we design a new streaming -approximation with memory, which implies a -approximation streaming algorithm running in space . We thus obtain a much better approximation than for Vector Bin Packing with a reasonable amount of memory (although to compute the actual makespan from our input summary, it takes time doubly exponential in ). Our algorithm is not based on rounding, as in the aforementioned algorithms, but on combining small jobs into containers, and the approximation guarantee of this approach is at least , which we demonstrate by an example. We describe the algorithm for Vector Scheduling in Section 4.
2 Related Work
We give an overview of related work in offline, online, and sublinear algorithms, and highlight the differences between online and streaming algorithms. Recent surveys of Christensen et al.  and Coffman et al.  have a more comprehensive overview.
2.1 Bin Packing
Offline approximation algorithms.
Bin Packing is an NP-complete problem and indeed it is NP-hard even to decide whether two bins are sufficient or at least three bins are necessary. This follows by a simple reduction from the Partition problem and presents the strongest inapproximability to date. Most work in the offline model focused on providing asymptotic -approximation algorithms, which use at most bins. In the following, when we refer to an approximation for Bin Packing we implicitly mean the asymptotic approximation. The first polynomial-time approximation scheme (PTAS), that is, a -approximation for any , was given by Fernandez de la Vega and Lueker . Karmarkar and Karp  provided an algorithm which returns a solution with bins. Recently, Hoberg and Rothvoß  proved it is possible to find a solution with bins in polynomial time.
The input for Bin Packing can be described by numbers, corresponding to item sizes. While in general these sizes may be distinct, in some cases the input description can be compressed significantly by specifying the number of items of each size in the input. Namely, in the High-Multiplicity Bin Packing problem, the input is a set of pairs , where for , is the number of items of size (and all ’s are distinct). Thus, encodes the number of item sizes, and hence the size of the description. The goal is again to pack these items into bins, using as few bins as possible. For constant number of sizes, , Goemans and Rothvoß  recently gave an exact algorithm for the case of rational item sizes running in time , where is the largest multiplicity of an item or the largest denominator of an item size, whichever is the greater.
While these algorithms provide satisfying theoretical guarantees, simple heuristics are often adopted in practice to provide a “good-enough” performance. First Fit , which puts each incoming item into the first bin where it fits and opens a new bin only when the item does not fit anywhere else achieves -approximation . For the high-multiplicity variant, using an LP-based Gilmore-Gomory cutting stock heuristic [22, 23] gives a good running time in practice  and produces a solution with at most bins. However, neither of these algorithms adapts well to the streaming setting with possibly distinct item sizes. For example, First Fit has to remember the remaining capacity of each open bin, which in general can require space proportional to OPT.
Vector Bin Packing proves to be substantially harder to approximate, even in a constant dimension. For fixed , Bansal, Eliáš, and Khan  showed an approximation factor of . For general , a relatively simple algorithm based on an LP relaxation, due to Chekuri and Khanna , remains the best known, with an approximation guarantee of . The problem is APX-hard even for , and cannot be approximated within a factor better than for any fixed  if is arbitrarily large. Hence, our streaming -approximation for Vector Bin Packing asymptotically achieves the offline lower bound.
Sublinear-time approximation schemes constitute a model related to, but distinct from, streaming algorithms. Batu, Berenbrink, and Sohler  provide an algorithm that takes weighted samples, meaning that the probability of sampling an item is proportional to its size. It outputs an asymptotic -approximation of OPT. If uniform samples are also available, then sampling items is sufficient. These results are tight, up to a factor. Later, Beigel and Fu  focused on uniform sampling of items, proving that samples are sufficient and necessary, where SIZE is the total size of all items. Their approach implies a streaming approximation scheme by uniform sampling of the substream of big items. However, the space complexity in terms of is not stated in the paper, but we calculate this to be for a constant . Moreover, samples are clearly needed to estimate the number of items with size close to . Note that our approach is deterministic and substantially different than taking a random sample from the stream.
Online and streaming algorithms are similar in the sense that they are required to process items one by one. However, an online algorithm must make all its decisions immediately — it must fix the placement of each incoming item on arrival.222Relaxations which allow a limited amount of “repacking” have also been considered . A streaming algorithm can postpone such decisions to the very end, but is required to keep its memory small, whereas an online algorithm may remember all items that have arrived so far. Hence, online algorithms apply in the streaming setting only when they have small space cost, including the space needed to store the solution constructed so far. The approximation ratio of online algorithms is quantified by the competitive ratio.
For Bin Packing, the best possible competitive ratio is substantially worse than what we can achieve offline or even in the streaming setting. Balogh et al.  designed an asymptotically -competitive algorithm, while the current lower bound on the asymptotic competitive ratio is . This (relatively complicated) online algorithm is based on the Harmonic algorithm , which for some integer classifies items into size groups . It packs each group separately by Next Fit, keeping just one bin open, which is closed whenever the next item does not fit. Thus Harmonic can run in memory of size , unlike most other online algorithms which require maintaining the levels of all bins opened so far. Its competitive ratio tends to approximately as goes to infinity. Surprisingly, this is also the best possible ratio if only a bounded number of bins is allowed to be open for an online algorithm , which can be seen as the intersection of online and streaming algorithms.
Offline approximation algorithms.
Makespan Scheduling is strongly NP-complete , which in particular rules out the possibility of a PTAS with time complexity . After a sequence of improvements, Jansen, Klein, and Verschae  gave a PTAS with time complexity , which is essentially tight under the Exponential Time Hypothesis (ETH) .
For constant dimension , Vector Scheduling also admits a PTAS, as shown by Chekuri and Khanna . However, the running time is of order . The approximation scheme for a fixed was improved to an efficient PTAS, namely to an algorithm running in time , by Bansal et al. , who also showed that the running time cannot be significantly improved under ETH. In contrast our streaming -space algorithm computes an input summary maintaining -approximation of the original input. This respects the lower bound, since to compute the actual makespan from the summary, we still need to execute an offline algorithm, with running time doubly exponential in . The best known approximation ratio for large is [27, 30], while -approximation is not possible in polynomial time for any constant and arbitrary , unless NP = ZPP.
For the scalar problem, the optimal competitive ratio is known to lie in the interval [1, 25, 29, 19], which is substantially worse than what can be done by a simple streaming -approximation in space . Interestingly, for Vector Scheduling, the algorithm by Im et al.  with ratio actually works in the online setting as well and needs space only during its execution (if the solution itself is not stored), which makes it possible to implement it in the streaming setting. This online ratio cannot be improved as there is a lower bound of [30, 4], whereas in the streaming setting we can achieve a -approximation with a reasonable memory (or even for a fixed ). If all jobs have sufficiently small size, we improve the analysis in  and show that the online algorithm achieves -approximation; see Section 4.
3 Bin Packing
For an instance , let be the number of items in , let be the total size of all items in , and let be the number of bins used in an optimal solution for . Clearly, . For a bin , let be the total size of items in . For a given , we use to hide factors logarithmic in and , i.e., to denote .
We first briefly describe the approximation scheme of Fernandez de la Vega and Lueker , whose structure we follow in outline. Let be an instance of Bin Packing. Given a precision requirement , we say that an item is small if its size is at most ; otherwise, it is big. Note that there are at most big items. The rounding scheme in , called “linear grouping”, works as follows: We sort the big items by size non-increasingly and divide them into groups of items (the first group thus contains the biggest items). In each group, we round up the sizes of all items to the size of the biggest item in that group. It follows that the number of groups and thus the number of distinct item sizes (after rounding) is bounded by . Let be the instance of High-Multiplicity Bin Packing consisting of the big items with rounded sizes. It can be shown that , where is the set of big items in (we detail a similar argument in Section 3.1). Due to the bounded number of distinct item sizes, we can find a close-to-optimal solution for efficiently. We then translate this solution into a packing for in the natural way. Finally, small items are filled greedily (e.g., by First Fit) and it can be shown that the resulting complete solution for is a -approximation.
Karmarkar and Karp  proposed an improved rounding scheme, called “geometric grouping”. It is based on the observation that item sizes close to should be approximated substantially better than item sizes close to . We present a version of such a rounding scheme in Section 3.1.2.
Our algorithm follows a similar outline with two stages (rounding and finding a solution for the rounded instance), but working in the streaming model brings two challenges: First, in the rounding stage, we need to process the stream of items and output a rounded high-multiplicity instance with few item sizes that are not too small, while keeping only a small number of items in the memory. Second, the rounding of big items needs to be done carefully so that not much space is “wasted”, since in the case when the total size of small items is relatively large, we argue that our solution is close to optimal by showing that the bins are nearly full on average.
Input summary properties.
More precisely, we fix some that is used to control the approximation guarantee. During the first stage, our algorithm has one variable which accumulates the total size of all small items in the input stream, i.e., those of size at most . Let be the substream consisting of all big items. We process and output a rounded high-multiplicity instance with the following properties:
There are at most item sizes in , all of them larger than , and the memory required for processing is .
The -th biggest item in is at least as large as the -th biggest item in (and the number of items in is the same as in ). This immediately implies that
Any packing of can be used as a packing of (in the same number of bins),
In words, 2 means that we are rounding item sizes up and, together with 3, it implies that the optimal solution for the rounded instance approximates well. The last property is used in the case when the total size of small items constitutes a large fraction of the total size of all items. Note that can be thought of as bin space “wasted” by rounding.
Observe that the succinctness of the rounded instance depends on . First, we show a streaming algorithm for rounding with . Then we improve upon it and give an algorithm with , which is essentially the best possible, while guaranteeing an error of introduced by rounding (elaborated on in Section 3.2). More precisely, we show the following:
Before describing the rounding itself and proving Lemma 1, we explain how to use it to calculate an accurate estimate of the number of bins.
Calculating a bound on the number of bins after rounding.
First, we obtain a solution of the rounded instance . For instance, we may round the solution of the linear program introduced by Gilmore and Gomory [22, 23], and get a solution with at most bins. Or, if item sizes are rational numbers, we may compute an optimal solution for by the algorithm of Goemans and Rothvoß ; however, the former approach appears to be more efficient and more general. In the following, we thus assume that uses at most bins.
We now calculate a bound on the number of bins in the original instance. Let be the total free space in the bins of that can be used for small items. To be precise, equals the sum over all bins in of . Note that the capacity of bins is capped at , because it may happen that all small items are of size while the packing leaves space of just under in any bin. Then we would not be able to pack small items into these bins. Reducing the capacity by removes this issue. On the other hand, if a small item does not fit into a bin, then the remaining space in the bin is smaller than .
Let be the total size of all small items in the input stream. If , then all small items surely fit into the free space of bins in (and can be assigned there greedily by First Fit). Consequently, we output that the number of bins needed for the stream of items is at most , i.e., the number of bins in solution for . Otherwise, we need to place small items of total size at most into new bins and it is easy to see that opening at most bins for these small items suffices. Hence, in the case , we output that bins are sufficient to pack all items in the stream.
We prove that the number of bins that we output in either case is a good approximation of the optimal number of bins, provided that is a good solution for .
We analyze the two cases of the algorithm:
Case : In this case, small items fit into the bins of and . For the inequality , observe that the packing can be used as a packing of items in (in a straightforward way) with no less free space for small items by property 2. Thus .
To upper bound , note that
where the second inequality follows from property 3 and the third inequality holds as is a subinstance of .
Case : Recall that . We again have that can be used as a packing of with no less free space for small items. Thus, the total size of small items that do not fit into bins in is at most and these items clearly fit into bins. Hence, .
For the other inequality, consider starting with solution for , first to (almost) fill up the bins of with small items of total size , then using additional bins for the remaining small items. Note that in each bin, except the last one, the unused space is less than , thus the total size of items in and small items is more than . Finally, we replace items in by items in and the total size of items decreases by by property 4. Hence, . Rearranging and using , we get
Considered together, these two cases both meet the claimed bound. ∎
3.1 Processing the Stream and Rounding
The streaming algorithm of the rounding stage makes use of the deterministic quantile summary of Greenwald and Khanna . Given a precision and an input stream of numbers , their algorithm computes a data structure which is able to answer a quantile query with precision . Namely, for any , it returns an element of the input stream such that the rank of is , where the rank of is the position of in the non-increasing ordering of the input stream.333Note that if appears more times in the stream, its rank is an interval rather than a single number. Also, unlike in , we order numbers non-increasingly, which is more convenient for Bin Packing. The data structure stores an ordered sequence of tuples, each consisting of an input number and valid lower and upper bounds on the true rank of in the input sequence.444More precisely, valid lower and upper bounds on the rank of can be computed easily from the set of tuples. The first and last stored items correspond to the maximum and minimum numbers in the stream, respectively. Note that the lower and upper bounds on the rank of any stored number differ by at most and upper (or lower) bounds on the rank of two consecutive stored numbers differ by at most as well. The space requirement of is , however, in practice the space used is observed to scale linearly with . (Note that an offline optimal data structure for -approximate quantiles uses space .) We use data structure to construct our algorithm for processing the stream of big items.
3.1.1 Simple Rounding Algorithm
We begin by describing a simpler solution with , resulting in a rounded instance with item sizes. Subsequently, we introduce a more involved solution with smaller space cost. The algorithm uses a quantile summary structure to determine the rounding scheme. Given a (big) item from the input, we insert it into . After processing all items, we extract from the set of stored input items (i.e., their sizes) together with upper bounds on their rank (where the largest size has highest rank 1, and the smallest size has least rank ). Note that the number of big items in is less than as each is of size more than . Let be the number of items (or tuples) extracted from ; we get that . Let be the output pairs of an item size and the bound on its rank, sorted so that . We define the rounded instance with at most item sizes as follows: contains items of size for each , plus one item of size . See Figure 1 for an illustration.
We show that the desired properties 1-4 hold with . Property 1 follows easily from the definition of and the design of data structure . Note that the number of items is preserved. To show 2, suppose for a contradiction that the -th biggest item in is bigger than the -th biggest item in , whose size is for , i.e., (note that as is the smallest item in and is present only once in ). We get that the rank of item in is strictly more than , and as , we get a contradiction with the fact that is a valid upper bound on the rank of in .
Next, we give bounds for and , which are required by properties 3 and 4. We pack the biggest items in separately into “extra” bins. Using the choice of and , we bound the number of these items and thus extra bins by . Let be the remaining items in . We claim that that the -th biggest item in is bigger than the -th biggest item in with size equal to for . For a contradiction, suppose that , which implies that the rank of in is less than . Note that as is the smallest item in . Since we packed the biggest items from separately, one of the positions of in the ordering of is and so we have , where the first inequality holds by the construction of and the second inequality is by the design of data structure . It follows that . Combining this with , we obtain that the rank of in is less than , which contradicts that is a valid lower bound on the rank of .
3.1.2 Improved Rounding Algorithm
Our improved rounding algorithm reduces the number of sizes in the rounded instance (and also the memory requirement) from to . It is based on the observation that the number of items of sizes close to can be approximated with much lower accuracy than the number of items with sizes close to 1, without affecting the quality of the overall approximation. This was observed already by Karmarkar and Karp .
Proof of Lemma 1.
Let . We first group big items in groups by size such that in group there are items with sizes in . That is, the size intervals for groups are , etc. Let , , be the number of big items in group ; clearly, . Note that the total size of items in group is in . Summing over all groups, we get in particular that
For each group , we use a separate data structure with , where is the quantile summary from  with precision . So when a big item of size arrives, we find such that and insert into . After processing all items, for each group , we do the following: We extract from the set of stored input items (i.e., their sizes) together with upper bounds on their rank. Let be the pairs of an item size and the upper bound on its rank in group , ordered as in the simpler algorithm so that . We have
An auxiliary instance is formed by items of size for plus one item of size . To create the rounded instance , we take the union of all auxiliary instances , . Note that the number of item sizes in is
We show that the desired properties 1-4 are satisfied. Property 1 follows easily from the definition of as the union of instances and the design of data structures . To see property 2, for every group , it holds that the -th biggest item in group in is at least as large as the -th biggest item in group in . Indeed, for any , is a valid upper bound on the rank of in group in and ranks of items of size in group in are at least . Moreover, the number of items is preserved in every group. Hence, overall, the -th biggest item in cannot be smaller than the -th biggest item in .
Next, we prove properties 3 and 4, i.e., the bounds on and on . For each group , we pack the biggest items in with size in group into “extra” bins, each containing items, except for at most one extra bin which may contain fewer than items. This is possible as any item in group has size at most . Using the choice of and (1), we bound the total number of extra bins by
Let be the remaining items in . Consider group and let and be the items with sizes in in and in , respectively. We claim that the -th biggest item in is at least as large as the -th biggest item in with size equal to for . For a contradiction, suppose that , which implies that the rank of in is less than . Note that as is the smallest item in . Since we packed the largest items from separately, we have , where the last inequality is by the design of data structure . It follows that . Combining it with , we obtain that the rank of in is less than , which contradicts that is a valid lower bound on the rank of . Hence, the claim holds for any group and it immediately implies and .
3.2 Bin Packing and Quantile Summaries
In the previous section, the deterministic quantile summary data structure from  allows us to obtain a streaming approximation scheme for Bin Packing. We argue that this connection runs deeper.
We start with different scenarios for which there exist better quantile summaries. First, if all big item sizes belong to a universe , then it can be better to use the quantile summary of Shrivastava et al. , which provides a guarantee of on the space complexity, where is the precision requirement. Thus, by using copies of this quantile summary in the same way as in Section 3.1.2, we get a streaming -approximation algorithm for Bin Packing that runs in space .
Second, if we allow the algorithm to use randomization and fail with probability , we can employ the optimal randomized quantile summary of Karnin, Lang, and Liberty , which, for a given precision and failure probability , uses space and does not provide a -approximate quantile for some quantile query with probability at most . In particular, using copies of their data structure with precision and failure probability in the same way as in Section 3.1.2 gives a streaming -approximation algorithm for Bin Packing which fails with probability at most and runs in space .
More intriguingly, the connection between quantile summaries and Bin Packing also goes in the other direction. Namely, we show that a streaming -approximation algorithm for Bin Packing with space bounded by (or ) implies a data structure of size for the following Estimating Rank problem: Create a summary of a stream of numbers which is able to provide a -approximate rank of any query , i.e., the number of items in the stream which are larger than , up to an additive error of . Observe that a summary for Estimating Rank is essentially a quantile summary and we can actually use it to find an approximate quantile by doing a binary search over possible item names. However, this approach does not guarantee that the item name returned will correspond to one of the items present in the stream.
The reduction from Estimating Rank to Bin Packing goes as follows: Suppose that all numbers in the input stream for Estimating Rank are from interval (this is without loss of generality by scaling) and let be a query in . For each such (in the Estimating Rank instance), we introduce two items of size (in the Bin Packing instance). In the stream for Bin Packing, after the items (two copies each of ) are inserted in the same order as in the stream for Estimating Rank, we then insert a further items, all of size . Observe first that no pair of the first items can be placed in the same bin, so we must open at least bins, two for each of . Since , and , we can place at most one of the items of size in a bin with in it, provided , i.e. . Thus, we can pack a number of the -sized items, equivalent to , in the first bins. This leaves items, all of size . We pack these optimally into additional bins, for a total of bins.
We claim that a -approximation of the optimum number of bins provides a -approximate rank of . Indeed, let be the number of bins returned by the algorithm and let be the estimate of . We have that the optimal number of bins equals and thus . By using and rearranging, we get
Since the right-hand side can be upper bounded by (provided that ), is a -approximate rank of . Hence, the memory state of an algorithm for Bin Packing after processing the first items (of sizes ) can be used as a data structure for Estimating Rank.
In  we show a space lower bound of for comparison-based data structures for Estimating Rank (and for quantile summaries as well).
Theorem 3 (Theorem 13 in ).
For any , there is no deterministic comparison-based data structure for Estimating Rank which stores items on any input stream of length .
We conclude that there is no comparison-based streaming algorithm for Bin Packing which stores items on any input stream (recall that in our reduction). Note that our algorithm is comparison-based if we employ the comparison-based quantile summary of Greenwald and Khanna , except that it needs to determine the size group for each item, which can be done by comparisons with for integer values of . Nevertheless, comparisons with a fixed set of constants does not affect the reduction from Estimating Rank (i.e., the reduction can choose an interval to avoid all constants fixed in the algorithm), thus the lower bound of applies to our algorithm as well. This yields near optimality of our approach, up to a factor of . Finally, we remark that the lower bound of for randomized comparison-based quantiles summaries  translates to Bin Packing as well.
3.3 Vector Bin Packing
As already observed by Fernandez de la Vega and Lueker , a -approximation algorithm for (scalar) Bin Packing implies a -approximation algorithm for Vector Bin Packing, where items are -dimensional vectors and bins have capacity in every dimension. Indeed, we split the vectors into groups according to the largest dimension (chosen arbitrarily among dimensions that have the largest value) and in each group we apply the approximation scheme for Bin Packing, packing just according to the largest dimension. Finally, we take the union of opened bins over all groups. Since the optimum of the Bin Packing instance for each group is a lower bound on the optimum of Vector Bin Packing, we get that that the solution is a -approximation.
This can be done in the same way in the streaming model. Hence there is a streaming algorithm for Vector Bin Packing which outputs a -approximation of OPT, the offline optimal number of bins, using memory. By scaling , there is a -approximation algorithm with memory. We can, however, do better by one factor of .
There is a streaming -approximation for Vector Bin Packing algorithm that uses memory.
Given an input stream of vectors, we create an input stream for Bin Packing by replacing each vector by a single (scalar) item of size . We use our streaming algorithm for Bin Packing with precision which uses memory and returns a solution with at most scalar bins. Clearly, bins are sufficient for the stream of vectors, since in the solution for we replace each item by the corresponding vector and obtain a valid solution for .
Finally, we show that for which it is sufficient to prove that as . Namely, from an optimal solution for , we create a solution for with at most bins. For each bin in , we split the vectors assigned to into groups according to the largest dimension (chosen arbitrarily among those with the largest value) and for each group we create bin with vectors in group . Then we just replace each vector by an item of size and obtain a valid solution for with at most bins. ∎
Interestingly, a better than -approximation using sublinear memory, which is rounding-based, is not possible, due to the following result in . (Note that the result requires that the numbers in the input vectors can take arbitrary values in , i.e., vectors do not belong to a bounded universe.)
Theorem 5 (Implied by the proof of Theorem 2.2 in ).
Any algorithm for Vector Bin Packing that rounds up large coordinates of vectors to types cannot achieve better than -approximation, where is the number of vectors.
It is an interesting open question whether or not we can design a streaming -approximation with memory or even with memory.
4 Vector Scheduling
4.1 Streaming Algorithm by Combining Small Jobs
We provide a novel approach for creating an input summary for Vector Scheduling (and hence also Makespan Scheduling by inclusion), based on combining small items into containers, which works well even in a large dimension. Our streaming algorithm stores all big jobs and all containers, created from small items, that are relatively big as well. Thus, there is a bounded number of big jobs and containers, and the space used is bounded as well. We show that this simple summarization preserves the optimal makespan up to a factor of for any . Take , since for there is a trivial streaming algorithm that just sums up the vectors of all jobs to get the optimal makespan. We assume that the algorithm knows (an upper bound on) in advance.
For and , the algorithms works as follows: For each , it keeps track of the total load of all jobs in dimension , denoted . Note that the optimal makespan satisfies . Assume for simplicity that when a new job arrives, ; if not, we rescale every quantity by this maximum. Hence, the optimum makespan for jobs that arrived so far is at least one, while for any (an alternative lower bound on OPT is the maximum norm of a job seen so far, but our algorithm does not use this).
Let ; the constant hidden in follows from the analysis below. We also ensure that . We say that a job with vector is big if ; otherwise it is small. The algorithm stores all big jobs (i.e., the full vector of each big job), while it aggregates small jobs into containers, and does not store any small job directly. A container is simply a vector that equals the sum of vectors for small jobs assigned to this container, and we ensure that . Furthermore, container is closed if , otherwise, it is open. As two open containers can be combined into one (open or closed) container, we maintain only one open container. We execute a variant of the Next Fit algorithm to pack the containers, adding the incoming small job into the open container, where it always fits as any small vector satisfies . All containers are retained in the memory.
When a new small job arrives or when a big job becomes small, we assign it in the open container. If this container becomes closed, we open a new, empty one. Moreover, it may happen that a previously closed container becomes open again. In this case, we combine open containers as long as we have at least two of them. This completes the description of the algorithm.
For packing the containers, we may also use another algorithm, such as First Fit, which also packs small jobs into a closed container if it fits. This may lead to having a lower number of containers in some cases. However, our upper bound of on the approximation factor lost by this summarization technique holds for any algorithm for packing the containers, as long as they do not exceed the capacity of containers, equal to . Moreover, the space bound holds if there is a bounded number of containers with .
Properties of the input summary.
After all jobs are processed, we assume again that , which implies that . Since any big job and any closed container, each characterized by a vector , satisfy , it holds that there are at most big jobs and closed containers. As at most one container remains open in the end and any job or container is described by numbers, the space cost is .
We now analyze the maximum approximation factor that can be lost by this summarization. Let be the resulting instance formed by big jobs and containers with small items (i.e., the input summary), and let be the original instance, consisting of jobs in the input stream. We show that and are close together, up to a factor of . Note, however, that we still need to execute an offline algorithm to get (an approximation of) , which is not an explicit part of the summary.
The crucial part of the proof is to show that containers for small items can be assigned to machines so that the loads of all machines are nearly balanced in every dimension, especially in the case when containers constitute a large fraction of the total load of all jobs. To capture this, let be the total load of containers in dimension (equal to the total load of small jobs). Let be the instance consisting of all containers in . The following lemma establishes the approximation factor.
Supposing that , the following holds:
There is a solution for instance with load at most in each dimension on every machine.
(i) We obtain the solution from the randomized online algorithm by Im et al. . Although this algorithm has ratio on general instances, we show that it behaves substantially better when jobs are small enough. In a nutshell, this algorithm works by first assigning each job to a uniformly random machine and if the load of machine exceeds a certain threshold, then the job is reassigned by Greedy. The online Greedy algorithm works by assigning jobs one by one, each to a machine so that the makespan increases as little as possible (breaking ties arbitrarily).
Let . We assume that each machine has its capacity of in each dimension split into two parts: The first part has capacity in dimension for the containers assigned randomly, and the second part has capacity in all dimensions for the containers assigned by Greedy. Note that Greedy cares about the load in the second part only.
The algorithm assigns containers one by one as follows: For each container , it first chooses a machine uniformly and independently at random. If the load of the first part of machine already exceeds in some dimension , then is passed to Greedy, which assigns it according to the loads in the second part. Otherwise, the algorithm assigns to machine .
As each container satisfies , it holds that randomly assigned containers fit into capacity in any dimension on any machine. We show that the expected amount of containers assigned by Greedy is small enough so that they fit into machines with capacity of , which in turn implies that there is a choice of random bits for the assignment so that the capacity for Greedy is not exceeded. The existence of a solution with capacity in each dimension will follow.
Consider a container and let be the machine chosen randomly for . We claim that for any dimension