Figure 7 shows a merge sort being carried out on a list - AQA - GCSE Computer Science - Question 8 - 2023 - Paper 1
Question 8
Figure 7 shows a merge sort being carried out on a list.
Figure 7
42 31 52 26
42 31 52 26
31 42 26 52
26 31 42 52
Explain how the merge sort algorithm works.
Worked Solution & Example Answer:Figure 7 shows a merge sort being carried out on a list - AQA - GCSE Computer Science - Question 8 - 2023 - Paper 1
Step 1
The list is (repeatedly) divided into sub-lists (half the size / at the midpoint) until each sub-list is of length 1 (singleton lists)
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
To initiate the merge sort algorithm, the input list is split into smaller sub-lists. This division continues recursively until all the sub-lists are of length one. Each individual element forms a singleton list that can be easily sorted.
Step 2
The algorithm compares / sorts individual elements as pairs;
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Once the list is divided into singleton sub-lists, the algorithm proceeds to compare these individual elements in pairs. Each pair is evaluated to determine their order, allowing for the sorting of elements as they are merged back together.
Step 3
(After comparing) the individual items are then (repeatedly) merged back together into sub-lists
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
After comparing and sorting the individual elements, the pairs are merged back into larger sub-lists. This merging process combines the sorted pairs, maintaining order through repeated comparisons.
Step 4
(Finally), one list is produced in the right order (which is the sorted list);
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The merging continues until all sub-lists are combined into one final list. This list represents the original input but is now fully sorted, achieving the objective of the merge sort algorithm.