Algorithms (Edexcel A-Level Further Mathematics): Revision Notes
10.1.3 Bin Packing Algorithms
What Are Bin Packing Algorithms?
Bin packing algorithms are used to solve problems where items of varying sizes must be placed into a fixed number of bins, each with a maximum capacity while minimising the number of bins used.
Types of Bin Packing Algorithms
-
First-Fit Algorithm Place each item in the first bin that has enough space.
-
First-Fit Decreasing (FFD) Algorithm Sort the items in descending order first, then apply the first-fit algorithm.
- Full Bin Packing Look for combinations of items that exactly fill a bin, then pack the remaining items using another method (e.g., first-fit).
Worked Examples
Example 1: First-Fit Algorithm
You have items of sizes to pack into bins of capacity .
Step 1: Place in bin 1.
- Bin 1:
- Remaining space:
Step 2: Place in bin 2.
- Bin 2:
- Remaining space:
Step 3: Place in bin 2 (fits in the remaining space).
- Bin 2:
- Remaining space:
Step 4: Place in bin (fits in the remaining space).
- Bin 1:
- Remaining space:
Step 5: Place in bin 3.
- Bin 3:
- Remaining space:
Result:
- Bin 1:
- Bin 2:
- Bin 3:
Example 2: First-Fit Decreasing Algorithm
You have the same items as before:
Step 1: Sort items in decreasing order:
Step 2: Place in bin 1.
- Bin 1:
- Remaining space:
Step 3: Place in bin 2.
- Bin 2:
- Remaining space:
Step 4: Place in bin 3.
- Bin 3:
- Remaining space:
Step 5: Place in bin 2.
- Bin 2:
- Remaining space:
Step 6: Place in bin 1.
- Bin 1:
- Remaining space:
Result:
- Bin 1:
- Bin 2:
- Bin 3:
Example 3: Full Bin Packing
You have items of sizes
Step 1: Look for combinations that fill a bin completely:
(Bin 1)
Step 2: Pack remaining items using first-fit:
- Bin 2:
- Bin 3:
Result:
- Bin 1:
- Bin 2:
- Bin 3:
Efficiency and Comparison
| Algorithm | Advantages | Disadvantages |
|---|---|---|
| First-Fit | Simple and quick to implement. | May not minimise bins effectively. |
| First-Fit Decreasing | Often gives better results than first-fit. | Sorting adds overhead. |
| Full Bin Packing | Efficient if exact combinations exist. | Requires extra effort to find combinations. |
Applications of Bin Packing Algorithms
- Storage Optimisation: Allocating files to storage devices.
- Logistics: Packing items into containers for shipping.
- Scheduling: Assigning tasks to processors in computing.
Note Summary
Common Mistakes
- Incorrect sorting in FFD: Ensure items are sorted in descending order before applying the first fit.
- Overlooking exact combinations in full bin packing: Use combinations only when feasible.
- Confusion about remaining space: Always update the remaining space in bins after placing items.
- Not testing with multiple methods: Some problems may benefit from comparing the results of different algorithms.
- Stopping prematurely: Ensure all items are packed.
Key Formulas
- Bin Packing Goal: Minimise the number of bins such that:
-
First-Fit Steps**:** Place each item into the first bin that has enough space.
-
First-Fit Decreasing Steps: Sort items in descending order, then apply first-fit.
-
Full Bin Packing Steps: Identify exact combinations for full bins, then use another algorithm for the remaining items.