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 middle
2 odd length? first list gets middle
3 repeat until every item is alone
4 merge neighbouring pairs of lists
5 no partner? copy it down
6 repeat until one list is left

Variables

lists=1phase=startlongest list=7

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.

1 / 8

Press Next to go one stage at a time, or Play to watch the whole sort run.

Step 1 of 8: Here’s the whole jumbled list. Merge sort starts by splitting it. Keep one eye on the order of the numbers as it goes..

Watch out: Odd number of items? The first list takes the middle item. That’s why 50 joins the first list at the first split, and why 3 stays with 64 when 64, 3, 19 is split.

Where does the sorting happen?

Be honest: what do you think?

Merge sort has two phases: splitting, then merging. By the end, the list is in order.

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

Your turn: one merge

Merge two sorted lists yourself

Merge the sorted lists 4, 6, 7 (list 1) and 2, 5, 9 (list 2) into one sorted list.

  1. Make an empty list for the merged items. The front items are 4 (list 1) and 2 (list 2).
  2. missing step
Which line is step 2?

Find the faulty line

Something goes missing

Sort 35, 12, 48, 7, 26, 51, 9 into ascending order using a merge sort. Show every stage.

A student’s answer — which line goes wrong?

Merge sort or bubble sort?

Merge sortvsBubble sort

Tap a row to see why it matters.

Focus

Speed on a large data set

Merge sort

Generally much faster

Bubble sort

Generally much slower

The insight

This is merge sort’s big selling point, and the bigger the data set, the more it shows.

Memory needed

Merge sort

More, because new lists are made each time a list is split or two lists are merged

Bubble sort

Less than merge sort

How hard it is to write

Merge sort

More complex

Bubble sort

Simpler

Speed on a small data set

Merge sort

Can be slower, because the data has to be broken apart first

Bubble sort

Can be faster, because it avoids merge sort’s overhead of breaking the data apart

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

1Split in the middle until every item stands alone. Odd number of items? The first list gets the middle one.
2Splitting puts nothing in order. All of the sorting happens during merging.
3To merge: compare the two front items, move the lower one, and copy the rest across when one list runs out.
4No partner at a stage? Copy that list down to the next stage.
5Faster than bubble sort on large data sets, but more memory and more complex to write.

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?
A sorting algorithm that repeatedly splits data into smaller lists, then merges pairs of lists, putting the items in order as they are merged.
What are the two phases of merge sort?
Splitting, then merging.
How does the splitting phase work?
Each list is split in the middle into two lists, and this repeats until every item is in a list of its own.
A list with an odd number of items is split. Which list gets the middle item?
The first list.
Why does splitting stop when every item is on its own?
A list of one item is already sorted.
What does merging do?
It combines two already sorted lists into one longer sorted list.
During a merge, how do you decide which item moves next?
Compare the first items of the two lists and move the lower one into the merged list.
During a merge, one list becomes empty. What happens next?
Copy each item left in the other list into the merged list, in order.
At a stage of merging, one list has no partner. What happens to it?
It is copied down to the next stage of merging.
When does the merging phase end?
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.
On a large data set, how does merge sort usually compare with bubble sort for speed?
Merge sort generally performs much faster.
Why does merge sort need more memory than bubble sort?
New lists are made each time a list is split or two lists are merged.
Why can bubble sort be faster than merge sort on a small data set?
Merge sort has the overhead of breaking apart the data before it can sort it.

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 Edexcel GCSE Computer Science topics

See the full Edexcel Computer Science curriculum →

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.