Mathster Maths topics Free worksheets Coverage Mathster for schools

Maths topics › A level Further Maths › D1 and algorithms

Find the order of an algorithm and use it to estimate how long the algorithm will take

A level Further Maths · D1 and algorithms

A question

A bubble sort is used to put a list of \(n\) items into order.

(a) Find the greatest number of comparisons the bubble sort can make when \(n = 35\).  

(b) What is the order of the bubble sort?  

(c) The number of items is multiplied by \(10\). By about what factor is the run time of the bubble sort multiplied?  

(d) A process applies a first-fit bin packing to \(n\) items, followed by a bubble sort. What is the order of the whole process?  

Free worksheet

10 questions on this objective, ready to print.

Download the worksheet (PDF)

We use this address to send you the answers, and for news only if you tick the box.

Worked solution

The working

  1. (a) In the worst case the passes make \(34, 34 - 1, \ldots, 2, 1\) comparisons, a total of \(\dfrac{1}{2}n(n-1) = \dfrac{1}{2} \times 35 \times 34 = 595\).
  2. (b) \(\dfrac{1}{2}n(n-1) = \dfrac{1}{2}n^2 - \dfrac{1}{2}n\). The \(n^2\) term dominates, so the bubble sort has quadratic order.
  3. (c) For quadratic order the time is multiplied by about \(10^2 = 100\).
  4. (d) One algorithm is carried out after the other, so their times add. The higher order dominates the sum: the process has order \(n^2\). (Orders are multiplied only when one algorithm is carried out inside the other.)

Answer: (a) 595 (b) quadratic (c) 100 (d) n^2

Mathster is maths homework, practice and assessment for schools, with animated worked solutions. Try Mathster free for 60 days →

Objectives from the AS and A level subject content for further mathematics (Department for Education). Contains public sector information licensed under the Open Government Licence v3.0.