CSFG
English Deutsch Beta Español Beta język polski (2.6.0)
Chapters Curriculum Guides Appendices

Complexity and Tractability
12.5. Bin packing problem

Complexity and Tractability

  • 12.1. What's the big picture?
  • 12.2. Algorithms, problems, and speed limits
  • 12.3. Tractability
  • 12.4. The Travelling Salesman Problem
  • 12.5. Bin packing problem
  • 12.6. Other intractable problems
  • 12.7. The whole story!
  • 12.8. Further reading

The bin packing problem is another intractable problem that is encountered in many different forms in everyday life. In the bin packing problem there are a number of items of varying sizes and the goal is to minimise the number of bins required to fit all the items. A real life example of this would be packing boxes into the back of a truck.

There is no known tractable solution to this problem, which means that we only currently have exponential-time algorithms that work out the minimum number of bins needed. However, there are a number of heuristics that can very quickly give a non-optimal solution. One of these is the (greedy) first fit algorithm. This algorithm uses the following steps:

  1. Select an item.
  2. Place it in the first bin that has space available for it. If there are no bins with space, add it to a new bin.

These steps are repeated until there are no items left.

A variation of the first fit algorithm involves sorting the items in decreasing order first. This means the largest items are packed first.

Try out these algorithms or your own ideas using this interactive:

Thumbnail of Bin Packing interactive

Bin Packing

Previous:
The Travelling Salesman Problem
Next:
Other intractable problems

Looking for something for primary schools? Check out CS Unplugged.

The Computer Science Field Guide is an online interactive resource for high school students learning about computer science.

Useful Links

  • About
  • Chapters
  • Interactives
  • Curriculum Guides

Community

  • Twitter
  • YouTube
  • GitHub

Help

  • Search
  • Glossary
  • Feedback

Switch to teacher mode

English | Deutsch | Español | język polski (2.6.0)

The Computer Science Field Guide material is open source on GitHub, and this website's content is shared under a Creative Commons Attribution-ShareAlike 4.0 International license. The Computer Science Field Guide is a project by the Computer Science Education Research Group at the University of Canterbury, New Zealand. Icons provided generously by icons8.

3.12.6

This definition is not available in English, sorry!