Date | November 2021 | Marks available | 3 | Reference code | 21N.1.SL.TZ0.6 |
Level | SL | Paper | 1 | Time zone | no time zone |
Command term | Explain | Question number | 6 | Adapted from | N/A |
Question
Explain how data is sorted by the selection sort.
Outline one difference between a bubble sort algorithm and a selection sort algorithm.
Markscheme
Award [3 max]
The selection sort algorithm maintains two subarrays of a given array, the subarray which holds already sorted elements;
And the subarray which is unsorted;
In every iteration, the minimum element (considering ascending order OR maximum element considering descending order) from the unsorted subarray is found/selected;
And then swapped with the item in the next position (at the appropriate place / in the last position) to be filled in the sorted subarray;
OR
The selection sort algorithm searches through the entire array for the smallest (considering ascending order OR the largest element considering descending order) element;
When found, it (the smallest/largest element) is swapped with the first element of the array;
Then searches for the smallest / largest element in the remaining array (an array without the first element) and swap it with the second element;
This process repeats on the remaining items (searches for the smallest / largest element in the remaining array (an array without first and second elements)) and swap it with the third element, and so on);
Award [2 max]
Bubble sort swaps adjacent items;
selection sort finds the next smallest (each time it goes through the list);
Bubble sort can exit early/ is faster if already the list is sorted;
selection sort will need to complete the procedure for the entire list every time;
(The efficiency of Bubble and selection sort is different when applied on already sorted list) in the best-case bubble sort takes an order of N time;
whereas selection sort consumes an order of N2 time (where N is the number of items on the list));
Note: To award marks for such an answer it should be evident that the list is already sorted OR the term 'the best-case' should appear because the worst-case /average-case complexity/efficiency is same in both algorithms (O(N2)).
Examiners report
Some very good descriptions of how the Selection Sort works were seen, with the vast majority of candidates achieving some marks. Many candidates achieved all three marks.
The vast majority of candidates were able to state a difference between the Bubble Sort and Selection Sort algorithms and how they sort data.