GCSE · Computer Science · Edexcel · Spec 1CP2
Merge sort
A huge pile of exam scripts to sort? Merge sort’s plan sounds like cheating: break it into bits so small they’re already sorted, then rebuild it in order.
Watch it run
Seven numbers fall apart, then come back in order
A merge sort of 43, 21, 14, 50, 64, 3, 19. The method sits on the left. Underneath, the list is rebuilt one stage at a time.
Make a call before you press Next: will the list get 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 jumbled list. Merge sort starts by splitting it. Keep one eye on the order of the numbers as it goes.
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.
Pull the list apart until every item stands alone. Then put it back together, in order, one merge at a time.
What you need to know
- Merge sort is a sorting algorithm with two phases: splitting first, then merging.
- Splitting cuts a list in the middle into two lists, again and again, until every item stands alone.
- Odd number of items? The first list takes the middle item, so seven items split into four, then three.
Have a goA list of six items gets its first split. How many items go in each list? Now try it with eleven items.
Six: 3 and 3. Eleven: 6 then 5.
Six is even, so it halves cleanly. Eleven is odd, so the first list takes the middle item and ends up one bigger, not the second.
- A list of one item is already sorted. That’s where splitting stops, and nothing has been put in order yet.
Have a goYour mate splits 9, 2, 7 into 9, 2 and 7 and says, “Nice, that’s a bit more sorted now.” Are they right?
Nope. 9, 2 | 7 is in exactly the same order as before.
A split only cuts in the middle. Nothing is compared or moved, so not a single item gets closer to its place until the merging starts.
- Merging combines two sorted lists: compare the two front items, move the lower one into the merged list, repeat.
- When one list is empty, copy every item left in the other list across, in order.
Have a goMerge 3, 8 with 5, 6. Which number is the third one to move into the merged list?
6, giving 3, 5, 6 so far (then 8 is copied across).
Compare the fronts every time: 3 beats 5, then 5 beats 8, then 6 beats 8. 8 doesn’t go early just because its list started with the lowest number.
- Lists are merged one pair at a time, stage by stage, until one list is left. No partner? Copy it down.
- Merge sort is divide and conquer: break a problem into smaller parts until each is simple enough to solve directly.
- Compared with bubble sort, it’s generally much faster, especially on large data sets, but more complex to write.
- It needs more memory, because new lists are made at every split and merge. On small data sets, bubble sort can be faster.
The big picture
Merge sort sorts a list in two phases. First it splits: each list is cut in the middle (odd number of items? the first list takes the middle one) until every item stands alone. Then it merges: pairs of sorted lists are combined stage by stage by comparing the two front items and moving the lower one, and when one list runs out, the rest of the other is copied across. A list with no partner at a stage is copied down. It’s a divide and conquer algorithm: generally much faster than bubble sort, especially on large data sets, but more complex to write and hungrier for 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
Gluing two lists end to end. Both are sorted, so it feels fine, but 21, 43 glued to 14, 50 gives 21, 43, 14, 50. A merge compares the two front items and moves the lower one, again and again, copying the rest across only when one list is empty.
Memory hook
Two queues, each lined up shortest to tallest, squeeze through one door. The shorter front person always goes next; 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 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 24 October 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.