Contents · 0% complete
Algorithms: Sorting and Bin Packing
An algorithm is a finite list of precise instructions. Bubble sort compares neighbours and swaps; quick sort splits around a pivot. Bin packing puts items into the fewest bins: first-fit, first-fit decreasing (FFD) and full-bin methods, compared with the lower bound .
Learning objectives
- Trace an algorithm given in words or as a flow chart.
- Carry out bubble sort, quick sort and binary search.
- Apply first-fit, first-fit decreasing and full-bin packing; find lower bounds.
- Use the order of an algorithm to estimate run times.
You must load boxes of 6, 5, 4, 3 and 2 kg into crates holding 10 kg each. What's the fewest crates possible?
Core idea
A removal firm has boxes of different weights and vans with a weight limit. Trying every arrangement would take forever. Instead they follow a short, precise recipe that gives a good answer fast. That recipe is an algorithm.
An algorithm is a finite sequence of precise steps. Sorting algorithms put lists in order; bin-packing algorithms fill containers. We judge them by correctness, by how close to optimal they get, and by how their run time grows with the input size (order).
1. Sorting
Carry out the first pass of a bubble sort (ascending) on .
- Goal
- List after pass 1.
- Strategy
- Compare neighbours left to right; swap if out of order.
- Swap.
- Swap twice more.
- In order; no swap.
- Each pass fixes one more item at the end, so needs one fewer comparison.
- Sum of the first integers.
2. Bin packing
- where
- round up to the next whole number.
Pack into bins of capacity .
- Goal
- Number of bins.
- Strategy
- Sort descending, then first-fit.
- 5 doesn't fit with 6.
- First bin with room.
- is full.
Three methods, from quickest to most careful.
A cubic-order algorithm takes s for items. Estimate for .
Summary
- Bubble sort: comparisons.
- Quick sort: pivots.
- Bin packing: compare with .
- Order predicts scaling.
- Algorithm
- Finite list of precise instructions.
- Heuristic
- Method that gives a good, not necessarily optimal, answer.
- Order
- How run time grows with input size.
Key formulae
Worked examples
Explore the graph
- is the number of items. The steeper curve is bubble sort's worst case, .
- Quick sort's typical grows far more slowly.
Quadratic vs .
Common mistakes
Optimal bin packing
FFD: close enough, and done before lunch.
Exam tip
Guided practice
Practice questions
More questions on every skill in this subtopic are in the question bank under Practise.
Challenge
Summary
- Bubble sort: neighbour swaps.
- Quick sort: pivots.
- Lower bound: total ÷ capacity, round up.
- FFD usually beats first-fit.
Quick quiz
Same topic, different board
- Specification
- A level Further Mathematics 9FM0
- Where
- Decision 1 · Algorithms and graph theory
- Expected
- Follow and trace algorithms (flow charts, text); bubble sort, quick sort, binary search; first-fit, first-fit decreasing and full-bin packing; lower bounds; order of an algorithm.
- Calculator
- Permitted; show enough working to earn the method marks.
- Typical style
- Edexcel often opens with a routine part and builds to a "show that" or "prove" part.
- Open in
- YMA01 · WDM119FM0 · Option
Past paper questions
No past paper questions are tagged to this subtopic yet. We add papers every week.
Browse past papersSalam Academy original content · Content status: reviewed and published. Syllabus mapping: Pearson Edexcel 9FM0, First teaching 2017 (official specification).