Bin Packing: Lower Bounds, First Fit, First Fit Decreasing and Full Bins | OCR A Level Further Maths notes

Free preview: Bin Packing: Lower Bounds, First Fit, First Fit Decreasing and Full Bins

Bin Packing and the Lower Bound

Year 1 (AS) for OCR B (MEI). For Edexcel and OCR A, check your own specification for which parts are AS and which are A level.

Let's start with a real job. A removal firm has boxes of different masses and crates that each hold 20 kg. Every crate costs money to move. How few crates can it use?

  • The bin packing problem: pack items of given sizes into bins of the same capacity, using as few bins as possible.
  • The "bins" can be anything: crates, lorries, CDs filled with songs, time slots filled with jobs, lengths of wood cut into pieces.
  • No item can be split, and no bin can go over its capacity.
  • For big problems there is no known quick algorithm that always finds the best packing, so we use heuristics: quick methods that give good, but not always best, packings (you met this word in the first note on algorithms).

Our example

  • Nine boxes, masses in kg: A 11, B 8, C 7, D 5, E 4, F 12, G 7, H 9, I 13.
  • Crate capacity: 20 kg.

Before packing anything, let's ask: what is the fewest crates we could possibly need? That number is called a lower bound.

Step 1: the lower bound

  • A lower bound is a number the answer cannot be smaller than.
  • However cleverly we pack, the crates must hold the total mass.
  • Total: 11+8+7+5+4+12+7+9+13=76 kg.

lower bound=⌈total of the itemsbin capacity⌉

  • The symbol ⌈⌉ means round up to the next whole number (if it is already whole, leave it).
  • Here 76÷20=3.8, so the lower bound is 4 crates.
  • Why round up? 3 crates hold at most 60 kg, which is not enough, so we need at least 4.

Diagram: The items total 76 kg and each crate holds 20 kg, so 76 20 = 3.8.

What the picture shows

  1. The items total 76 kg and each crate holds 20 kg, so 76÷20=3.8.
  2. Wrong: rounding down to 3 leaves 16 kg with nowhere to go, because 3 crates hold only 60 kg.
  3. Right: always round a lower bound UP. 3.8 tells you 3 is not enough, so at least 4 crates are needed.

๐Ÿ’ก In plain words

  • The lower bound is the number of bins you would need if you could pour the items in like water.
  • No packing can use fewer bins than this. If a packing uses exactly this many, it must be optimal (the best possible).

๐Ÿ“ Show the division

Write "76÷20=3.8, so at least 4 bins". The calculation and the rounding up each earn credit. Never round down: 3.8 bins means 3 are not enough.

โœ๏ธ YOUR TURN 1

Try this first:

Seven parcels of sizes 6, 9, 4, 7, 3, 8 and 5 units go into containers of capacity 15. Find a lower bound for the number of containers.

Answer:

  • Total: 6+9+4+7+3+8+5=42.
  • 42÷15=2.8, so at least 3 containers.
  • Check: 2 containers hold only 30, which is less than 42.

โœ๏ธ YOUR TURN 2

Try this first:

Items of size 12, 18, 10 and 20 are to be packed into bins of capacity 15. What is wrong with this problem, before you even work out a lower bound?

Answer:

The item of 18 and the item of 20 are bigger than a bin, so they cannot be packed at all. Always check that every item is at most the capacity. (If they could be packed, the formula would give ⌈60÷15⌉=4.)

The First Fit Algorithm

Now let's actually pack. The simplest sensible rule: take each item as it comes and drop it in the first crate that has room. That is first fit.

The first fit recipe

  1. Take the items in the order given. Why: first fit makes no attempt to rearrange; that is what makes it quick.
  2. Put each item into the first bin (bin 1, then bin 2, and so on) that has enough room left for it. Why: earlier bins get topped up before we open new ones.
  3. If no bin has room, start a new bin.
  4. Every new item starts checking from bin 1 again. Why: a small item may still squeeze into an early bin.

๐Ÿ‘€ Watch me do it: first fit on the crates (capacity 20)

What I writeWhy I do it
A = 11 into bin 1 (11)No bins yet, so open bin 1.
B = 8 into bin 1 (19)11 + 8 = 19, which is at most 20.
C = 7 into bin 2 (7)Bin 1: 19 + 7 = 26, too much. Open bin 2.
D = 5 into bin 2 (12), E = 4 into bin 2 (16)Each time bin 1 is checked first and is too full (19 + 5 = 24, 19 + 4 = 23).
F = 12 into bin 3 (12)Bin 1 is at 19, bin 2 at 16: neither has room for 12.
G = 7 into bin 3 (19)Bin 1: 26, bin 2: 23, both too much. Bin 3: 12 + 7 = 19.
H = 9 into bin 4 (9)Bins are at 19, 16, 19, so none has room for 9.
I = 13 into bin 5 (13)Does not fit with H (22), or anywhere else.
First fit uses 5 binsBin 1: A, B. Bin 2: C, D, E. Bin 3: F, G. Bin 4: H. Bin 5: I.

Unlock the full note: start 7 days free.

Log in or subscribe to read the rest of this note. Members also get the AI tutor, practice quizzes, mock exams and flashcards for this topic.

Log in ยท Subscribe ยท Start free trial

All notes in Algorithms, Complexity, Sorting and Bin Packing

  1. What Is an Algorithm? Flow Charts, Pseudocode and Trace Tables
  2. Bubble Sort, Shuttle Sort and Quick Sort Step by Step
  3. Bin Packing: Lower Bounds, First Fit, First Fit Decreasing and Full Bins
  4. The Order of an Algorithm: Counting Comparisons and Predicting Run Times

What's inside for this topic

4 teacher notes, 80 practice questions, 52 flashcards, 2 quizzes.

Get the full notes, every practice question, flashcards, quizzes and mock papers.

Start your free 7-day trial

Questions? Chat with us on WhatsApp ยท Try one live lesson

Previous note: Bubble Sort, Shuttle Sort and Quick Sort Step by Step Next note: The Order of an Algorithm: Counting Comparisons and Predicting Run Times

All OCR A Level Further Maths topics ยท A Level Further Maths