CS11-07 Computer Science Watch
Bubble or merge: which and why
In this lesson
Bubble or merge: how to compare bubble sort and merge sort, with worked examples and the mistakes examiners report. AQA 8525 GCSE. Searching and sorting 7 of 7. More at https://scholafly.com
By the end: Compare bubble sort and merge sort, giving each one's advantages and disadvantages with a reason attached: merge sort is much quicker on large lists but needs extra memory and is harder to write; bubble sort is simpler to code, uses almost no extra memory and can be quick on small or nearly sorted lists, but is slow on large ones.
What it covers
- 0:00 Intro: bubble or merge: which and why
- 0:36 Bubble or merge: which and why
- 1:34 Bubble or merge: which and why: speed
- 2:52 Memory and code
- 4:29 Qualifying a point
Key words
About this video
Bubble or merge: which and why | GCSE Computer Science | CS11-07
Bubble or merge: how to compare bubble sort and merge sort, with worked examples and the mistakes examiners report.
AQA 8525 GCSE. Searching and sorting 7 of 7.
More at https://scholafly.com
Watch first: CS11-05 - https://youtu.be/xBljIFPZNeI
Video code: CS11-07 (search "ScholaFly CS11-07")
#GCSEComputerScience #SearchingAndSorting #BubbleOrMergeWhichAndWhy
For teachers
This GCSE Computer Science lesson teaches bubble or merge: which and why. By the end, students should be able to compare bubble sort and merge sort, giving each one's advantages and disadvantages with a reason attached: merge sort is much quicker on large lists but needs extra memory and is harder to write; bubble sort is simpler to code, uses almost no extra memory and can be quick on small or nearly sorted lists, but is slow on large ones. It works through three worked examples and the mistakes examiners report.
Exam board specification references:
AQA 8525
- 3.1.4
Read the transcript
Was Barack Obama right about bubble sort? In two thousand seven, then running for president, he was asked at Google how to sort a million numbers, and answered: I think the bubble sort would be the wrong way to go. So bubble sort is the bad one, full stop? Not for ten names on a whiteboard, where it can be the better pick. A full answer says what each sort is better at, and when.
One course prints this comparison as its own statement. For anyone else it is optional, and still a good test of both sorts. Both sorts can be held in one picture each before they are weighed up. Bubble sort compares neighbours, swaps any pair in the wrong order, and repeats passes until a pass makes no swaps. It works inside the one list. Merge sort splits the list down to single items, then merges them back up by comparing front items. It needs extra lists to hold the parts as it works. A point in this comparison is complete when it says what the sort is better or worse at, when that matters, and why.
Speed is merge sort's advantage, and counting comparisons shows how big it gets. On eight items in the worst order, a bubble sort that makes full passes can need fifty-six comparisons. A merge sort needs at most seventeen. Now stretch the list to a thousand items, and count again. On a thousand items, is the gap about twice, ten times or a hundred times? About a hundred times. The slower method can need around a million checks, while the faster one stays under ten thousand. Merge sort's advantage, then, in full: it is much quicker on large lists, because it makes far fewer comparisons as the list grows. On a short list the gap shrinks to a handful of comparisons, and that is where bubble sort's own strengths start to count.
Memory and code are where bubble sort has the advantage. Bubble sort works inside the one list, and the only extra space it needs is one temporary place to hold a value during a swap. Merge sort needs extra lists to hold the parts while it splits and merges, so it uses more memory. Bubble sort is also simpler to code: two loops and a swap. Merge sort has to split, keep track of every part and merge them back, so it is harder to write. A phone with very little spare memory has to sort a short list of contacts. Which sort suits the phone and its twenty contacts, and why? Bubble sort is the better fit. It needs almost no extra memory, and with only twenty items the slower speed hardly shows. Now a server with plenty of memory and five million records: which sort? Merge sort, this time. Five million records is a big list, so far fewer comparisons wins, and the server can spare the room.
Two students explain why bubble sort suits ten names on a whiteboard. The first writes: it is simple. Bubble sort is simple: what does that point leave out? What it is simpler at, and when that matters. The second student writes: simpler to code, so it suits a short list. That says both, and giving both is called qualifying a point. One examiner's report records: There were some well written answers for the advantages or disadvantages of the bubble sort and the majority of students were able to identify at least one. Further on, it adds: Some students are still not qualifying their answers which means it is not clear what they mean, and so marks cannot always be given. The fix is the second student's habit: every point carries its what and its when, and its because where it has one. Another student writes: merge sort is better because it is more efficient. Pause and rewrite that merge sort sentence so it says what and when. One version: merge sort is quicker than bubble sort on large lists, because it makes far fewer comparisons as the list grows. Read it back. Quicker is the what, large lists is the when, and fewer comparisons is the because.
To close, four situations, and a sort to pick for each with its what, when and because. A smartwatch sorting ten step counts, with tiny memory: which sort, and why? Bubble again, because it uses almost no extra memory, and on ten values the speed gap hardly matters. Now a bank sorting millions of transactions overnight: which sort, and why? The merge sort, since on a list that large it makes far fewer comparisons, so it finishes much sooner. Try fixing this point: merge sort is complicated. What would make it count? Say what it is harder at, and why. Harder to code, because it has to split, keep track of every part and merge them back. One more: bubble sort for ten names on the whiteboard, but not for a million numbers. Why both? Ten names: simpler to code, almost no extra memory, and quick enough. A million numbers: merge sort makes far fewer comparisons, so the answer at Google was right.
If you are sorted on this one, a thumbs up says so, and it saves you rewatching it in the run-up to exams. If it is not there yet, save it and come back to it later in the week, when the two sorts have had time to settle.
That completes our chapter on Searching and sorting. Next chapter: Programming fundamentals. Hopefully that's next in your feed, but if not, search for ScholaFly C S twelve, oh oh.
Every other video is on scholafly.com too, easy to search by video code or by keyword. Whatever you're revising, go there and have a look, or, watch the next video.
Related terms
For: AQA GCSE 8525
On the specification
| Board | Spec | Statement |
|---|---|---|
| AQA GCSE 8525 | 3.1.4 | Sorting algorithms |
For teachers
This GCSE Computer Science lesson teaches bubble or merge: which and why. By the end, students should be able to compare bubble sort and merge sort, giving each one's advantages and disadvantages with a reason attached: merge sort is much quicker on large lists but needs extra memory and is harder to write; bubble sort is simpler to code, uses almost no extra memory and can be quick on small or nearly sorted lists, but is slow on large ones. It works through three worked examples and the mistakes examiners report.