GCSE · Computer Science · Edexcel · Spec 1CP2
Merge sort
Handed a huge pile of exam scripts to sort? Merge sort’s trick sounds like cheating: break the pile into bits so small they’re already sorted, then rebuild it carefully.
Watch it run
Seven numbers come apart, then come back in order
A merge sort of 43, 21, 14, 50, 64, 3, 19. The method is on the left. Underneath, the list builds up stage by stage.
Before you press Next: do you think the list gets any more sorted while it’s being split?
1 split each list in the middle2 odd length? first list gets middle3 repeat until every item is alone4 merge neighbouring pairs of lists5 no partner? copy it down6 repeat until one list is left
Variables
Output
start 43 21 14 50 64 3 19
Step 1: Here’s the whole unsorted list. Merge sort begins by splitting it. Keep an eye on the order of the numbers while it does.
Press Next to go one stage at a time, or Play to watch the whole sort run.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Break the list apart until every item stands alone. Then build it back up, in order, one merge at a time.
What you need to know
- Merge sort is a sorting algorithm with two phases: splitting, then merging.
- Splitting: a list is split in the middle into two lists. This repeats until every item is in a list of its own. If a list has an odd number of items, the first list takes the middle item.
- A list of one item is already sorted, so that is where splitting stops.
- Merging combines two sorted lists into one longer sorted list. Compare the first items of the two lists and move the lower one into the merged list. When one list is empty, copy the items left in the other list across in order.
- In the merging phase, lists are merged one pair at a time, stage by stage, until one ordered list is left. A list with no partner at a stage is copied down to the next stage.
- Merge sort is a divide and conquer algorithm: it breaks a problem into smaller and smaller parts until they are simple enough to solve directly.
- Compared with bubble sort, merge sort is generally much faster, especially on large data sets. But it is more complex to write and needs more memory, because new lists are made at every split and merge. On small data sets, simpler algorithms such as bubble sort can be faster.
The big picture
Merge sort puts a list in order in two phases. Splitting cuts each list in the middle, with the first list taking the middle item when the length is odd, until every item stands alone. Merging then combines pairs of sorted lists stage by stage: compare the front items, move the lower one, and copy the rest across when one list empties. A list with no partner at a stage is copied down. Merge sort is a divide and conquer algorithm: generally much faster than bubble sort, especially on large data sets, but more complex to write and it needs more memory.
Key points
Worked example
Problem
Use a merge sort to put 9, 4, 7, 1 into ascending order. Show each stage, and the comparisons in the final merge.
⚠ Watch out
Treating a merge as joining two lists end to end. A merge compares the front items of the two lists and moves the lower one, again and again. Only when one list is empty is the rest of the other list copied across.
Memory hook
Two queues, each lined up shortest to tallest, merge through one door: the shorter of the two front people always goes next, and when one queue runs out, the rest walk through. That’s a merge. Merge sort breaks the crowd into queues of one, then merges them back in pairs.
Check yourself
Without looking back, explain why merge sort bothers to split a list all the way down to single items, even though splitting doesn’t put anything in order.
Flashcards
(14)What is merge sort?
What are the two phases of merge sort?
How does the splitting phase work?
A list with an odd number of items is split. Which list gets the middle item?
Why does splitting stop when every item is on its own?
What does merging do?
During a merge, how do you decide which item moves next?
During a merge, one list becomes empty. What happens next?
At a stage of merging, one list has no partner. What happens to it?
When does the merging phase end?
What is a divide and conquer algorithm?
On a large data set, how does merge sort usually compare with bubble sort for speed?
Why does merge sort need more memory than bubble sort?
Why can bubble sort be faster than merge sort on a small data set?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.