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 item
split each of those lists in the middle (odd length: the first list gets the middle item)
WHILE more than one list is left
merge the lists in pairs (a list with no partner is copied to the next stage)
compare the front item of each list
place the item that comes first into the merged list
when one list is empty, copy the rest of the other list into the merged list
result = the one ordered list

Variables

lists=[5, 2, 8, 1, 9, 3, 7]stage=start

Step 1. One list of seven items, in no particular order. This first row is worked for you.

Step 1 of 15Called right: 0 of 7

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?

Link 1 of 4

First link · your turn

Before a merge starts, what do we already know about each of the two lists?

2
Locked — reveal the link above first
3
Locked — reveal the link above first
4
Locked — reveal the link above first

Computer Science · Sorting algorithms

So where does the sorting actually happen?

You have just watched a merge sort break a list into smaller and smaller lists, until every item was on its own.

Which of these is closest to what you think?
How sure are you?

Computer Science · Sorting algorithms

Now write the trace yourself

Write out a merge sort of 6, 3, 8, 2, 7 (smallest to largest). One row for each splitting stage, one row for each merging round.

  1. Start: [6, 3, 8, 2, 7]One list of five items. The first row is given.
  2. missing step
Which line is step 2?

Computer Science · Sorting algorithms

Which row went wrong?

A student merge sorted 6, 2, 9, 4 (smallest to largest). Their trace ends with a list that is missing an item. Find the row where it first went wrong.

A student's trace — which line goes wrong?

Merge sort vs bubble sort

Merge sortvsBubble sort

Start with the row people get wrong most often.

Focus

Small datasets

Merge sort

Can be slower, because of the overhead of having to break the data apart

Bubble sort

Simpler algorithms like this can be faster

The insight

So merge sort is not always the quickest. The splitting has a cost, and with only a few items that cost can outweigh the benefit.

Large datasets

Merge sort

Generally performs much faster

Bubble sort

Generally much slower than merge sort

How hard it is to write

Merge sort

More complex to write

Bubble sort

Simpler to write

Memory

Merge sort

Takes up extra space in memory, because new lists have to be created

Bubble sort

Merge sort is the one that pays this cost

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

1Split first, merge second: all the ordering happens in the merging.
2Splitting an odd-length list: the first list gets the middle item.
3A merge compares the two front items, places the one that comes first, and copies the rest across when a list runs out.
4Divide and conquer: break the problem down until each part is simple enough to solve directly.
5Merge sort is usually faster than bubble sort on large datasets, but more complex to write and needs more memory. On small datasets simpler algorithms can be faster.

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?
Splitting the list into smaller lists, then merging pairs of lists back together, ordering the items as they are merged.
How do you split a list in merge sort?
In the middle, into two lists. Keep splitting until each item is in a list of its own.
A list has an odd number of items. Which list gets the middle item when it is split?
The first list.
Is any ordering done while the list is being split?
No. Splitting only divides the list. The ordering happens as lists are merged.
What does merging do?
Combines two lists that are already in order into one longer ordered list.
How do you decide which item goes into the merged list next?
Compare the items at the front of both lists and place the one that comes first.
In a merge, one list has no items left but the other still has some. What now?
Copy the leftover items from the other list across into the merged list.
At the end of a merging stage, one list has no partner. What happens to it?
It is copied over to the next stage of merging pairs of lists.
When does a merge sort finish?
When all the lists have been merged into one ordered list.
What is a divide and conquer algorithm?
One that breaks a problem into smaller and smaller parts until they are simple enough to solve directly.
Why is comparing only the front items enough in a merge?
Both lists are already in order, so each front item is the smallest left in its list. The lower of the two is the smallest left overall.
When is merge sort generally faster than bubble sort?
On a list of data, especially a large dataset: generally much faster.
Why can simpler algorithms such as bubble sort or insertion sort beat merge sort on small data sets?
Merge sort has the overhead of having to break apart the data to be sorted.
What is the downside of merge sort?
It requires more memory, because new lists have to be created. It is also more complex to write than bubble 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 posted

More Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

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.