Figure 6 gives five numbers to arrange from the smallest to the largest. We try two sorting methods, compare them, and then think about hunting for a value in a sorted array of 2500 numbers.
Show bubble sort on the Figure 6 numbers: list the order after each change, between the printed start order and the sorted order.
Our own questions on this topic, marked straight away, so you see what to revise. Free now.
Show model answer for 06.1Hide model answer for 06.1
45 23 78 55 49
23 45 78 55 49
23 45 55 78 49
23 45 55 49 78
23 45 49 55 78How the marks are earned
- First changed row: 23 45 78 55 49.
- Second changed row: 23 45 55 78 49.
- Third changed row: 23 45 55 49 78 (the last row, 23 45 49 55 78, is the sorted result).
- Each correct change in the correct order earns one mark. Blanks for repeated values are ignored.
- Showing a whole pass as one row, so the rows are 23 45 55 49 78 then 23 45 49 55 78, earns 1 mark only.
- If the grid is not fully correct, the maximum is 2 marks.
- The first and last rows of the grid are printed on the paper, so writing them again earns nothing and loses nothing.
Why it scores
Bubble sort swaps neighbours that are in the wrong order. In pass one, 45 and 23 swap, then 78 and 55 swap, then 78 and 49 swap, which moves 78 to the end. In pass two, 55 and 49 swap, and the list is then in order.
Revise Bubble SortShow the merge stage of a merge sort on the Figure 6 numbers, row by row, down to one sorted row.
See how you would score on Merge SortShow model answer for 06.2Hide model answer for 06.2
45 23 78 55 49
[23 45] [55 78] [49]
[23 45] [49 55 78]
[23 45 49 55 78]How the marks are earned
- Pairs are sorted correctly, for example 23 45 and 55 78 (another correct pairing, such as 45 alone with 23 78 and 49 55, is equally accepted).
- One element is left on its own after the pairs are made, for example 49.
- Three or four elements are merged and sorted correctly, for example 49 55 78 or 23 45 55 78.
- If the sorted row is already given, or is written again, nothing is lost.
- If there are any errors, the maximum is 2 marks.
Why it scores
The first merge joins the five single values into sorted pairs, 23 45 and 55 78, with 49 left alone because there is nothing to pair it with. The lone 49 is then merged with the pair 55 78 to give 49 55 78. The last merge joins 23 45 with 49 55 78 into the sorted list.
Revise Merge SortCompare bubble sort with merge sort: give one point in bubble sort's favour and one against it.
See how you would score on Bubble SortShow model answer for 06.3Hide model answer for 06.3
Advantage: bubble sort needs fewer lines of code, so it is simpler to write and check.
Disadvantage: bubble sort is slower than merge sort on a long list, because it makes many passes of comparisons.
How the marks are earned
- Advantage, one of: simpler to code, needing fewer lines of code than merge sort; or often faster on small lists.
- Using less memory, with only one extra storage location where merge sort needs more, is also accepted as an advantage.
- Disadvantage, one of: bubble sort does not sort lists (especially large ones) as quickly as merge sort; or it is less efficient.
- An unqualified answer such as bubble sort is simple earns nothing.
Why it scores
Quoting the reason (fewer lines) is what stops the answer being the unqualified word simple.
The comparison with merge sort is what qualifies the answer.
Revise Bubble SortGive reasons binary search is a better choice than linear search on 2500 numbers kept in ascending order.
See how you would score on Binary SearchShow model answer for 06.4Hide model answer for 06.4
A linear search may have to look at all 2500 values, so on average binary search is much quicker.
A binary search checks the middle value and throws away half of the list each time. For 2500 values it needs at most about 12 checks.
How the marks are earned
- Binary search is quicker or more efficient, with or without saying on average, or linear search is slower since it could need to look at every one of the 2500 values.
- The value is found with fewer comparisons, or each check removes half of the remaining values. A figure such as about 12 checks at most is not needed for the mark.
Why it scores
This is the first mark: binary search is more efficient because linear search can check every value.
This is the second mark: fewer comparisons, with the halving idea and the number of checks.
Revise Binary Search