Decision Maths: Algorithms, Sorting and Bin Packing - Worksheets, Questions and Revision

12 original exam-style questions - 6 pages of questions with a full mark scheme - free printable PDF.

Download PDFJump to mark scheme (page 7)
« Previous: Core Pure: Polar Coordinates and Hyperbolic FunctionsNext: Decision Maths: Graphs, Trees and Minimum Spanning Trees »
Revision Library
revisionlibrary.co.uk
A-Level · Further Decision 1 (Algorithms, Sorting and Bin Packing)

FP.D1 Decision Maths: Algorithms, Sorting and Bin Packing

AQA 7367 · Calculator allowed · about 130 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.
1
The following list of seven numbers is to be sorted into ascending order:
58, 23, 91, 12, 67, 45, 34
(a)Perform a bubble sort on the list to sort it into ascending order. Show the list in full after each pass, and continue until you have completed one full pass in which no swaps are made.(4)
(b)State the total number of passes needed and the total number of comparisons made across all of these passes.(2)
(c)State the total number of swaps made during the whole sort, and explain why a bubble sort must include a final pass with no swaps before you can be certain the list is fully sorted.(2)
(Total for Question 1 is 8 marks)
2
This question compares how a bubble sort performs on the same set of six numbers arranged in two different orders.
(a)The marks (out of 60) scored by six students in a Further Maths mock exam are recorded in the order the papers were marked: 36, 14, 58, 22, 41, 9. Sort this list into ascending order using a bubble sort, showing the list in full after each pass. Continue until a pass with no swaps occurs, and state the total number of passes and the total number of swaps used.(5)
(b)The same six marks are instead given in the order 9, 14, 22, 36, 58, 41. Sort this list into ascending order using a bubble sort, showing the list after each pass, and state the number of passes needed this time.(3)
(c)By comparing your answers to parts (a) and (b), explain what this shows about the best-case and worst-case performance of a bubble sort on a list of n items.(2)
(Total for Question 2 is 10 marks)
3
A courier drives to eight different addresses in one shift. The distances, in miles, driven to reach each address, in the order the deliveries were planned, are:
34, 12, 55, 8, 41, 27, 63, 19
(a)Using the first item of each sublist as the pivot, perform a quicksort on this list to sort it into ascending order. At each stage, state the pivot used and the two resulting sublists (items less than the pivot, and items greater than or equal to the pivot). Continue until every sublist contains at most one item, then write out the final sorted list.(5)
(b)State the total number of comparisons used to complete the sort, given that each non-pivot item in a sublist is compared exactly once with that sublist's pivot.(2)
(c)State one advantage and one disadvantage of always choosing the first item of a sublist as the pivot, compared with other pivot-selection methods.(2)
(Total for Question 3 is 9 marks)
4
The following list shows the scores (out of 100) achieved by seven contestants in a coding competition:
72, 55, 89, 41, 67, 60, 78
(a)Using median-of-three pivot selection (at each stage, compare the first, middle and last items of the current sublist, and choose whichever of these three values is the median as the pivot), perform a quicksort on this list to sort it into ascending order. At each stage, state the three items compared, the pivot chosen, and the two resulting sublists. Write out the final sorted list.(5)
(b)Give one reason why choosing the pivot by the median-of-three method, rather than always using the first item of the sublist, can improve the efficiency of a quicksort, and describe a type of list for which this improvement is most noticeable.(2)
(Total for Question 4 is 7 marks)
5
Chidi works for a small courier company. On one shift, he must load parcels of the following weights, in kg, into delivery bins that can each hold a maximum of 10 kg:
6, 5, 4, 7, 3, 8, 2, 5
Figure (to be drawn): A row of numbered bins (crates), each labelled with capacity 10 kg, into which weights are packed in sequence.
(a)Apply the first-fit algorithm to the parcels in the order given, packing them into bins of capacity 10 kg. For each bin, show which parcels it contains. State the number of bins used.(4)
(b)Calculate the theoretical lower bound for the number of bins needed for this set of parcels, and compare it with your answer to part (a).(2)
(Total for Question 5 is 6 marks)
6
This question continues from question 5, using the same eight parcel weights and the same 10 kg bin capacity.
(a)Re-order Chidi's parcel weights into decreasing order of size, then apply the first-fit algorithm to this re-ordered list (this is called first-fit decreasing). Show the contents of each bin, and state the number of bins used.(3)
(b)State whether first-fit decreasing has achieved the lower bound found in question 5(b), and explain why sorting the weights into decreasing order before applying first-fit can reduce the number of bins needed, compared with using first-fit on the original order.(2)
(Total for Question 6 is 5 marks)
7
Freya, an art technician at a secondary school, has eight tins of paint with the following volumes, in litres, to store in crates that can each hold a maximum of 10 litres:
8, 2, 7, 3, 6, 4, 5, 5
(a)Calculate the theoretical lower bound for the number of crates needed to hold all eight tins.(2)
(b)Use a full-bin method: starting with the largest unallocated tin each time, try to find one or more other tins whose volumes sum to exactly fill the remaining space in that crate. Show the contents of each crate you form.(4)
(c)Compare your answer to part (b) with your lower bound in part (a), and state what this shows about this particular set of tin volumes.(1)
(Total for Question 7 is 7 marks)
8
Tomasz is helping his family move house. Some of the boxes have the following weights, in kg, and must be packed into crates that can each hold a maximum of 9 kg:
6, 5, 6, 5, 6, 6, 5, 5
(a)Calculate the theoretical lower bound for the number of boxes needed to pack these items.(2)
(b)Sort the list of weights into decreasing order and apply first-fit decreasing, packing into crates of capacity 9 kg. Show the contents of each crate, and state the number of crates used.(3)
(c)Explain why no packing method, including first-fit decreasing, can achieve the lower bound found in part (a) for this particular set of weights.(2)
(Total for Question 8 is 7 marks)
9
This question is about determining the order of an algorithm from timed test results.
(a)Ravi times how long Algorithm 1 takes to run on lists of different sizes, n. His results are shown below.

n = 10, time = 8 ms
n = 20, time = 32 ms
n = 40, time = 128 ms
n = 80, time = 512 ms

Use a doubling ratio test (comparing the run time each time n doubles) to estimate the order of Algorithm 1, giving your answer in the form O(nk).
(3)
(b)Ravi also tests Algorithm 2, obtaining the results below.

n = 5, time = 4 ms
n = 10, time = 32 ms
n = 20, time = 256 ms

Use the same method to estimate the order of Algorithm 2.
(2)
(c)A third algorithm has order O(n). It takes 15 ms to process a list of 200 items. Estimate how long it would take this algorithm to process a list of 800 items, showing your reasoning.(2)
(Total for Question 9 is 7 marks)
10
The following pseudocode describes an algorithm applied to a list of n numbers:

Step 1: Let List = [a list of n numbers]
Step 2: Let Max = List(1), Min = List(1)
Step 3: For i = 2 to n
Step 4: If List(i) > Max then Max = List(i)
Step 5: If List(i) < Min then Min = List(i)
Step 6: Next i
Step 7: Let Range = Max - Min
Step 8: Output Max, Min, Range
(a)State, in your own words, what this algorithm calculates for a given list of n numbers.(1)
(b)Trace this algorithm for List = [23, 45, 12, 67, 34, 9, 58], recording the values of Max and Min after each value of i from 2 to 7 is considered. Present your working as a trace table.(3)
(c)State the values output by the algorithm for Max, Min and Range.(1)
(d)State the order of this algorithm in terms of n, the number of items in the list, and justify your answer.(2)
(Total for Question 10 is 7 marks)
11
This question uses known comparison-count formulas to compare the efficiency of a bubble sort and a quicksort as the size of the list, n, grows large.
(a)The number of comparisons made by a bubble sort in the worst case, on a list of n items, is given by n(n - 1)/2. Calculate the worst-case number of comparisons for (i) n = 50, (ii) n = 200, (iii) n = 1024.(3)
(b)Given that n increased by a factor of 4 between parts (a)(i) and (a)(ii), show that the ratio of your two answers is consistent with the bubble sort's worst-case order of O(n2).(2)
(c)A quicksort, on average, makes approximately n log2(n) comparisons to sort a list of n items. Calculate the approximate number of comparisons a quicksort would make, on average, to sort a list of n = 1024 items.(2)
(d)By comparing your answer to part (c) with your answer to part (a)(iii), comment on the practical significance, for large n, of the difference in order between an O(n log n) algorithm and an O(n2) algorithm.(2)
(Total for Question 11 is 9 marks)
12
Aisha runs a small office-relocation company. For one client's move, the following box weights, in kg, must be packed into crates that can each hold a maximum of 20 kg, in the order the boxes are brought out of the office:
12, 9, 14, 7, 11, 8, 15, 6, 13, 10
Figure (to be drawn): A loading bay with a stack of ten labelled boxes and a row of crates awaiting packing.
(a)Calculate the theoretical lower bound for the number of crates needed.(2)
(b)Apply first-fit to the weights in the order given, packing into crates of capacity 20 kg. Show the contents of each crate, and state the number of crates used.(3)
(c)Sort the weights into decreasing order and apply first-fit decreasing, packing into crates of capacity 20 kg. Show the contents of each crate, and state the number of crates used.(3)
(d)Using a full-bin method, find as many crates as possible that can be exactly filled from the original ten weights, and state which items (if any) cannot be paired to exactly fill a crate.(3)
(e)Comment on what your answers to parts (b) to (d) show about the effectiveness of first-fit, first-fit decreasing and the full-bin method for this particular set of data.(2)
(Total for Question 12 is 13 marks)
Mark scheme · FP.D1 Decision Maths: Algorithms, Sorting and Bin Packing

Question 1

Question 2

Question 3

Question 4

Question 5

Question 6

Question 7

Question 8

Question 9

Question 10

Question 11

Question 12