The eight numbers in Figure 5 must be put in ascending order. A different task searches an array: it looks at the first item, halts if that item is the target, and otherwise goes on to the next item.
Show each stage of a merge sort that sorts the numbers in Figure 5 into ascending order.
Our own questions on this topic, marked straight away, so you see what to revise. Free now.
Show model answer for 03.1Hide model answer for 03.1
Divide
[2 7 3 1 9 6 5 4]
[2 7 3 1] [9 6 5 4]
[2 7] [3 1] [9 6] [5 4]
[2] [7] [3] [1] [9] [6] [5] [4]
Merge
[2 7] [1 3] [6 9] [4 5]
[1 2 3 7] [4 5 6 9]
[1 2 3 4 5 6 7 9]How the marks are earned
- One mark for each stage, up to 4. Brackets are not needed, but it must be clear which numbers form each group of 2, 4 or 8.
- BP1: the list is split into separate groups of one item. This may be done in several stages or all at once.
- BP2: the single items join into ordered pairs: 2 with 7, 1 with 3, 6 with 9 and 4 with 5.
- BP3: sorted groups of four are shown: 1 2 3 7 and 4 5 6 9.
- BP4: one finished list in ascending order, 1 to 7 and then 9, reached by a reasonable attempt at merging the two fours into an eight. That list shown with no merging steps, or made by another algorithm, earns nothing.
- Joining groups in the wrong order and sorting them afterwards does not earn BP3 or BP4.
- With no splitting shown at all, the starting list counts as already divided, so BP2 to BP4 can still be earned. A faulty split loses BP1 only.
- Using different numbers, or sorting into descending order, is penalised once and then followed through.
Why it scores
Merge sort first divides the list until every group holds one item. It then merges neighbouring groups, putting the numbers in order each time, until one sorted list remains.
Revise Merge SortTick one box in each of the three tables, on insertion sort, bubble sort and arrays, to give correct statements.
See how you would score on Bubble SortShow model answer for 03.2Hide model answer for 03.2
Insertion sort: the array is split into a part already in order and a part still to do
Bubble sort: it swaps two neighbours only when they sit the wrong way round
Array: the number of items it holds is set when it is declared
How the marks are earned
- One mark for each group, up to 3. A group with more than one box ticked earns nothing.
- Insertion sort: it uses an array with a sorted part and an unsorted part.
- Bubble sort: a pair is swapped only when the two values sit the wrong way round.
- Array: its length is fixed at the moment it is declared.
Why it scores
It takes each item from the unsorted part and inserts it in the right place in the sorted part. It does not start at the middle, and merging belongs to merge sort.
Swapping a pair that is already in order would undo the sort. Bubble sort only swaps a pair that is the wrong way round.
The size of an array is set when it is made. Its values can be changed while the program runs, and arrays can have more than one dimension.
Revise Bubble SortGive the name of the algorithm for searching that these steps describe.
See how you would score on Linear SearchShow model answer for 03.3Hide model answer for 03.3
Linear search
How the marks are earned
- Linear search. The word linear on its own is credited. Linear sort is not.
Identify one other condition that stops this search.
See how you would score on Linear SearchShow model answer for 03.4Hide model answer for 03.4
It stops when it reaches the end of the list, having checked every value without finding the target.
How the marks are earned
- The end of the list has been reached, or the last value has been checked, or every value has been checked. Adding that the target was not found is not needed.
- A bare answer that the value is not found or not in the list earns nothing. The idea of reaching the end or checking the whole list must be there.