GCSE · Computer Science · Eduqas · Spec C500QS
Merge sort
Here's a sorting algorithm that does no sorting while it splits the list. The order only appears as it rebuilds it. Be the algorithm first, then see why it works.
Computer Science · Sorting algorithms
Be the algorithm: merge sort a list by hand
Split the list all the way down, then merge it back up. At each marked step, make the call before the lists appear.
You are the algorithm now. Press Next to move through the sort. At a marked step, Next stops until you commit to what comes next. The page sorts nothing for you.
lists = [ the whole unsorted list ]WHILE any list has more than one itemsplit each of those lists in the middle (odd length: the first list gets the middle item)WHILE more than one list is leftmerge the lists in pairs (a list with no partner is copied to the next stage)compare the front item of each listplace the item that comes first into the merged listwhen one list is empty, copy the rest of the other list into the merged listresult = the one ordered list
Variables
Step 1. One list of seven items, in no particular order. This first row is worked for you.
Try the list of six afterwards: same algorithm, different data.
Why merging works
Reason it through
Why can a merge get away with comparing only the two front items?
First link · your turn
Before a merge starts, what do we already know about each of the two lists?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A sort that does no sorting while it splits, then puts everything in order as it merges back up.
What you need to know
- Merge sort has two parts: splitting the list up, then merging the pieces back together.
- Splitting only divides: cut each list in the middle into two lists, and keep going until every item is in a list of its own.
- With an odd number of items, the first list takes the middle item.
Have a goSplit [8, 5, 9, 2, 6] in the middle into two lists. Write down both before you look.
[8, 5, 9] and [2, 6]
Five items is odd, so the first list takes the middle item (9). It gets three items and the second list gets two.
- Nothing gets ordered while you split. The ordering happens as lists are merged.
- Merging combines two lists that are already in order into one longer ordered list.
- To merge, compare the items at the front of both lists and place the one that comes first into the new list.
Have a goMaya is merging [2, 7] with [3, 4], smallest to largest, and says, "I'll start by comparing the 7 with the 4, the big ones." Which two items should she compare, and which goes first?
She should compare 2 and 3, and 2 goes first.
A merge only compares the items at the front of the two lists, and the one that comes first goes into the merged list.
- When one list runs out, copy the items still left in the other list into the merged list.
- Keep merging pairs of lists until one ordered list is left. A list with no partner is copied to the next stage.
Have a goA merging stage starts with nine lists. How many lists are there once the stage is finished?
Five: four merged pairs, plus the ninth list copied across.
Lists are merged in pairs, and with an odd number one list has no partner, so it is copied to the next stage rather than dropped.
- Merge sort is a "divide and conquer" algorithm: break the problem into smaller and smaller parts until each is simple enough to solve directly.
- Compared with bubble sort, merge sort is usually faster on large lists, but it is more complex to write and needs extra memory.
The big picture
Merge sort has two parts. Splitting cuts the list in the middle, again and again, until every item is in a list of its own. Merging then combines pairs of lists that are already in order into longer ordered lists, by comparing their front items, until one ordered list is left. It is a divide and conquer algorithm that is usually much faster than bubble sort on big datasets, but harder to write and hungrier for memory.
Key points
Worked example
Problem
Two queues of numbers are each already in order: 2, 6, 9 and 4, 5. Combine them into a single queue in order, smallest first.
⚠ Watch out
Thinking the list gets sorted while it is being split. It does not. Splitting only cuts the list into smaller lists and the items stay in their original order. The ordering only starts at the first merge.
Memory hook
The knife never sorts anything. Chop it down to single items, then sort as you stitch it back together.
Check yourself
Merge [3, 8] and [5, 6, 9]. Which two items do you compare first, and what is left to copy once the first list runs out? (3 and 5; then 9.)
Flashcards
(14)What are the two parts of merge sort?
How do you split a list in merge sort?
A list has an odd number of items. Which list gets the middle item when it is split?
Is any ordering done while the list is being split?
What does merging do?
How do you decide which item goes into the merged list next?
In a merge, one list has no items left but the other still has some. What now?
At the end of a merging stage, one list has no partner. What happens to it?
When does a merge sort finish?
What is a divide and conquer algorithm?
Why is comparing only the front items enough in a merge?
When is merge sort generally faster than bubble sort?
Why can simpler algorithms such as bubble sort or insertion sort beat merge sort on small data sets?
What is the downside of merge sort?
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 Eduqas GCSE Computer Science topics
How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)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 23 November 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.