ArticleslgStudy

computer science

Bin packing problem

Bin packing problem is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Bin packing problem rather than just read about it. In short: The bin packing problem is an optimization problem, in which items of different sizes must be packed into a finite number of bins or containers, each of a fixed given capacity, in a way that minimizes the number of bins used. The problem has many applications, such as filling up containers, loading trucks with weight capacity constraints, creating file backups in media, splitting a network prefix into multiple subne…

Key takeaways

  • Bin packing problem belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Bin packing problem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Bin packing problem from memory before moving on to harder problems.

Reference excerpt

The bin packing problem is an optimization problem, in which items of different sizes must be packed into a finite number of bins or containers, each of a fixed given capacity, in a way that minimizes the number of bins used. The problem has many applications, such as filling up containers, loading trucks with weight capacity constraints, creating file backups in media, splitting a network prefix into multiple subnets, and technology mapping in FPGA semiconductor chip design. Computationally, the problem is NP-hard, and the corresponding decision problem, deciding if items can fit into a specified number of bins, is NP-complete. Despite its worst-case hardness, optimal solutions to very large instances of the problem can be produced with sophisticated algorithms. In addition, many approximation algorithms exist. For example, the first fit algorithm provides a fast but often non-optimal solution, involving placing each item into the first bin in which it will fit. It requires Θ(n log n) time, where n is the number of items to be packed. The algorithm can be made much more effective by first sorting the list of items into decreasing order (sometimes known as the first-fit decreasing algorithm), although this still does not guarantee an optimal solution and for longer lists may increase the running time of the algorithm. It is known, however, that there always exists at least one ordering of items that allows first-fit to produce an optimal solution. There are many variations of this problem, such as 2D packing, linear packing, packing by weight, packing by cost, and so on. The bin packing problem can also be seen as a special case of the cutting stock problem. When the number of bins is restricted to 1 and each item is characterized by both a volume and a value, the problem of maximizing the value of items that can fit in the bin is known as the knapsack problem. A variant of bin packing that occurs in practice is when items can share space when packed into a bin. Specifically, a set of items could occupy less space when packed together than the sum of their individual sizes. This variant is known as VM packing since when virtual machines (VMs) are packed in a server, their total memory requirement could decrease due to pages shared by the VMs that need only be stored once. If items can share space in arbitrary ways, the bin packing problem is hard to even approximate. However, if space sharing fits into a hierarchy, as is the case with memory sharing in virtual machines, the bin packing problem can be efficiently approximated. Another variant of bin packing of interest in practice is the so-called online bin packing. Here the items of different volume are supposed to arrive sequentially, and the decision maker has to decide whether to select and pack the currently observed item, or else to let it pass. Each decision is without recall. In contrast, offline bin packing allows rearranging the items in the hope of achieving a better packing once additional items arrive. This of course requires additional storage for holding the items to be rearranged.

Formal statement In Computers and Intractability Garey and Johnson list the bin packing problem under the reference [SR1]. They define its decision variant as follows. Instance: Finite set I of items, a size s(i)∈ℤ+ for each i∈I, a positive integer bin capacity B, and a positive integer K. Question: Is there a partition of I into disjoint sets I1,…,IK such that the sum of the sizes of the items in each Ij is B or less? Note that in the literature often an alternate, but not equivalent, notation is used, where B=1 and s(i)∈ℚ∩(0,1] for each i∈I. Furthermore, research is mostly interested in the optimization variant, which asks for the smallest possible value of K. A solution is optimal if it has minimal K. The K-value for an optimal solution for a set of items I is denoted by OPT(I) or just OPT if the set of items is clear from the context. A possible integer linear programming formulation of the problem is:

where yj=1 if bin j is used and xij=1 if item i is put into bin j.

Hardness of bin packing The bin packing problem is strongly NP-complete. This can be proven by reducing the strongly NP-complete 3-partition problem to bin packing. Furthermore, there can be no approximation algorithm with absolute approximation ratio smaller than 32 unless 𝖯=𝖭𝖯. This can be proven by a reduction from the partition problem: given an instance of Partition where the sum of all input numbers is 2T, construct an instance of bin packing in which the bin size is T. If there exists an equal partition of the inputs, then the optimal packing needs 2 bins; therefore, every algorithm with an approximation ratio smaller than ⁠3/2⁠ must return less than 3 bins, which must be 2 bins. In contrast, if there is no equal partition of the inputs, then the optimal packing needs at least 3 bins. On the other hand, bin packing is solvable in pseudo-polynomial time for any fixed number of bins K, and solvable in polynomial time for any fixed bin capacity B.

Approximation algorithms for bin packing To measure the performance of an approximation algorithm there are two approximation ratios considered in the literature. For a given list of items L the number A(L) denotes the number of bins used when algorithm A is applied to list L, while OPT(L) denotes the optimum number for this list. The absolute worst-case performance ratio RA for an algorithm A is defined as

RA≡inf⁡{r≥1:A(L)/OPT(L)≤r for all lists L}. On the other hand, the asymptotic worst-case ratio RA∞ is defined as

RA∞≡inf⁡{r≥1:∃N>0,A(L)/OPT(L)≤r for all lists L with OPT(L)≥N}. Equivalently, RA∞ is the smallest number such that there exists some constant K, such that for all lists L:

A(L)≤RA∞⋅OPT(L)+K. Additionally, one can restrict the lists to those for which all items have a size of at most α. For such lists, the bounded size performance ratios are denoted as RA(size≤α) and RA∞(size≤α). Approximation algorithms for bin packing can be classified into two categories:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Bin packing problem

Start with the simplest possible case. Write down what Bin packing problem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Bin packing problem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Bin packing problem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Bin packing problem

In research
Bin packing problem appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Bin packing problem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Bin packing problem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Bin packing, Optimization algorithms and methods, Strongly NP-complete problems, so understanding it makes those chapters shorter.
In everyday life
Look for Bin packing problem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Bin packing problem” →

How to study Bin packing problem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Bin packing problem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Bin packing problem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Bin packing problem in simple terms?

The bin packing problem is an optimization problem, in which items of different sizes must be packed into a finite number of bins or containers, each of a fixed given capacity, in a way that minimizes the number of bins used. The problem has many applications, such as filling up containers, loading…

Why does Bin packing problem matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Bin packing problem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Bin packing problem.

Tags

  • Bin packing
  • Optimization algorithms and methods
  • Strongly NP-complete problems

Keep exploring