Chapter 16 – Sorting algorithms – bubble and merge

AQA A level Computer Science
Teaching and Learning Resources
Chapter 16 – Sorting algorithms – bubble and merge
TASK QUESTIONS (WITH ANSWERS)
1
Explain how you could use a bubble sort and a merge sort to sort the following list of data:
12, 3, 4, 8, 2, 6, 10, 5
A bubble sort would compare the first two values and swap them if necessary. It would then
compare values two and three and swap them if necessary. When it had compared all pairs,
it would go through the list again as many times as necessary until the list was sorted.
A merge sort would break the list into eight lists each containing one item of data. It would
then compare the first two lists, placing the lower item first. It would continue this process
until the eight lists were re-assembled into one sorted list of eight items.
2
Explain why a bubble sort requires data to be stored in an array.
The bubble sort needs all the data in the same location and needs to identify the location of
each item in the list so that the swaps can take place.
3
Would a bubble sort or merge sort be the quickest way of sorting the list in Question 1?
Explain your answer.
This depends on the data being sorted in terms of whether it is stored in array, whether it
already has some order to it and how many values need sorting. For the small dataset in
Question 1, then a bubble sort would be quick and not require much memory.
4
What if there were 1 million items in a list? Which would be the quickest then? Explain your
answer.
In this case, a merge sort would be more efficient in terms of time as it would not need to
access the list as many times. However, it would require more memory than a bubble sort as
each intermediary list needs writing out and sorting, so they can be compared.
5
Both bubble and merge sorts use ‘iteration’ and a merge sort uses ‘recursion’. What do
these mean and why are they needed?
Iteration is the process of repeating a process. Both sort methods use iteration as they both
repeat processes to produce a fully sorted list.
Recursion is when a subroutine calls itself. A merge sort needs recursion as it repeats the
same process every time it splits up and them compares and re-assembles the list.
AQA A level Computer Science
© Hodder & Stoughton Limited 2015