Medium4 marksExtended Response
Fundamentals of algorithmsGeneralalgorithmssortingmerge sort

AQA GCSE · Question 08 · Fundamentals of algorithms

A list of numbers [5, 2, 8, 1, 9, 4] needs to be sorted using the merge sort algorithm. Explain how the merge sort algorithm works by describing the 'divide' and 'conquer' (merge) steps for this list.

How to approach this question

1. Start by explaining the "divide" phase. Show how the initial list is broken down into smaller and smaller lists until you have lists of a single element. 2. Next, explain the "conquer" or "merge" phase. Show how these single-element lists are combined back together. 3. Crucially, explain that when two lists are merged, their elements are compared and placed into the new list in the correct sorted order. 4. Continue this merging process until you are left with a single, fully sorted list.

Full Answer

The merge sort algorithm works using a "divide and conquer" strategy. 1. **Divide:** The list `[5, 2, 8, 1, 9, 4]` is recursively split in half until each sub-list contains only one element. - `[5, 2, 8]` and `[1, 9, 4]` - `[5]`, `[2, 8]` and `[1]`, `[9, 4]` - `[5]`, `[2]`, `[8]` and `[1]`, `[9]`, `[4]` At this point, each element is in its own list, which is considered sorted. 2. **Conquer (Merge):** The sub-lists are then repeatedly merged back together in sorted order. - `[2]` and `[8]` merge to `[2, 8]`. `[5]` and `[2, 8]` merge to `[2, 5, 8]`. - `[9]` and `[4]` merge to `[4, 9]`. `[1]` and `[4, 9]` merge to `[1, 4, 9]`. - Finally, the two sorted halves `[2, 5, 8]` and `[1, 4, 9]` are merged to produce the final sorted list: `[1, 2, 4, 5, 8, 9]`.
Merge sort is a classic sorting algorithm that exemplifies the "divide and conquer" paradigm. **1. The Divide Step:** The main list is treated as a problem to be solved. The algorithm's first step is to break this problem into smaller, more manageable sub-problems. It does this by splitting the list in half. It then takes each of those halves and splits them in half again. This process continues recursively until the lists cannot be split any further, which is when they each contain only one element. A list with one element is, by definition, already sorted. **2. The Conquer (Merge) Step:** Once the list is broken down into single-element sub-lists, the algorithm begins to "conquer" by merging them back together. When two sub-lists are merged, a new sorted list is created by comparing the elements from the two lists one by one and adding the smaller one to the new list. This ensures the newly created list is sorted. This merging process is repeated up the hierarchy until all the sub-lists have been merged back into a single list, which is now fully sorted.

Common mistakes

✗ Confusing merge sort with other sorting algorithms like bubble sort or insertion sort.\n✗ Only describing the splitting part and not the merging part (or vice-versa).\n✗ Failing to explain that the merging process itself is what sorts the elements.

Practice the full AQA GCSE Computer Science Paper 1 Python

31 questions · hints · full answers · grading

More questions from this exam