🔒
Unlock Everything
£7.99/month
or £59/year
Subscribe now →
🔢 Component 2 · 2.1 Algorithms
2.1.3d Algorithm Comparison
OCR J277 · GCSE Computer Science · ~10 min read
Notes
Video
Slides
Worksheet
Quiz

The Big Picture — Comparing OCR J277 Algorithms

OCR J277 requires you to compare the searching and sorting algorithms covered in the specification. You need to know their time complexity, space requirements, and when each is most suitable.

Search Algorithms — Linear vs Binary

PropertyLinear SearchBinary Search
Time complexityO(n)O(log n)
Sorted list required?NoYes — must be sorted
Best caseO(1) — target at index 0O(1) — target is midpoint
Worst caseO(n) — n comparisonsO(log n) — log₂n comparisons
Suitable for large data?No — slowYes — very efficient
Memory usageO(1)O(1)
Works on unsorted data?YesNo
Best use caseSmall/unsorted listsLarge sorted lists

Sort Algorithms — Bubble, Merge, Insertion

PropertyBubble SortMerge SortInsertion Sort
Worst caseO(n²)O(n log n)O(n²)
Best caseO(n) optimisedO(n log n)O(n)
Average caseO(n²)O(n log n)O(n²)
In-place?YesNo — O(n) extraYes
Stable?YesYesYes
Ease of implementationSimpleComplex (recursive)Simple
Good for large data?NoYesNo
Good for nearly sorted?OK (optimised)No benefitVery good
Good for small data?YesNo benefitYes

Time Complexity — At a Glance

n (items)O(n) — linearO(log n) — binaryO(n log n) — mergeO(n²) — bubble/insertion
1010333100
100100766410,000
1,0001,000109,9661,000,000
1,000,0001,000,0002020,000,0001,000,000,000,000

Which Algorithm to Choose? — Scenarios

Scenario 1: Search a sorted list of 1 million records
Binary search — O(log n) ≈ 20 comparisons vs 1,000,000 for linear search
Scenario 2: Search a small unsorted list of 10 items
Linear search — no need to sort first, list is small enough
Scenario 3: Sort 1,000,000 customer records for a database
Merge sort — O(n log n) vastly outperforms O(n²) at this scale
Scenario 4: Sort a small list of 10 items in a simple program
Bubble or insertion sort — simple to implement, negligible difference at n=10
Scenario 5: Sort a nearly-sorted list where memory is limited
Insertion sort — near O(n) for nearly sorted data, in-place (no extra memory)
Scenario 6: Sort a list, but memory is extremely limited
Bubble or insertion sort — both are in-place. Merge sort requires extra O(n) memory
Exam tip: When asked to "compare" or "evaluate" algorithms, consider: time complexity (best AND worst case), whether a sorted list is needed, memory usage (in-place or not), and suitability for the scenario. Don't just name the complexity — explain what it means. E.g. "binary search is O(log n), meaning for 1 million items it only needs about 20 comparisons." Always justify your recommendation in context.
⚠️ Common Mistakes
  • Saying binary search works on unsorted data — it does NOT
  • Saying merge sort is in-place — it is NOT (requires extra memory)
  • Claiming one algorithm is "always best" — context matters
  • Forgetting that O(n log n) is better than O(n²) — even though n log n "has n in it", it grows much slower
  • Not mentioning the sorted list requirement when comparing linear and binary search
✅ Notes completed!
Video coming soon
Click slide or press arrow keys to navigate

Worksheet — 2.1.3d Algorithm Comparison

8 questions · 20 marks

Q1State the time complexity of: (a) bubble sort worst case (b) merge sort (c) binary search (d) linear search[4]
✅ Mark scheme
(a) O(n²) [1] (b) O(n log n) [1] (c) O(log n) [1] (d) O(n) [1]
Q2A student needs to search a sorted list of 500,000 records. Which search algorithm should they use and why?[2]
✅ Mark scheme
Binary search [1] — it is O(log n), requiring approximately 19 comparisons vs 500,000 for linear search. The list is sorted, so binary search's pre-requirement is met [1].
Q3Explain why merge sort is preferred over bubble sort for sorting a large dataset.[3]
✅ Mark scheme
Merge sort is O(n log n) [1] while bubble sort is O(n²) [1]. For large n, O(n log n) is much more efficient — e.g. for 1 million items: ~20 million vs ~1 trillion operations [1].
Q4Give one advantage of bubble sort over merge sort.[1]
✅ Mark scheme
Any one: bubble sort is in-place (no extra memory required) [1]; simpler to implement [1]; O(n) best case with the swap flag optimisation (vs O(n log n) for merge sort) [1].
Q5A system has very limited memory and needs to sort a small list. Which sort algorithm should be used and why?[2]
✅ Mark scheme
Bubble sort or insertion sort [1] — both are in-place, requiring no extra memory beyond a small variable. Merge sort requires O(n) extra memory which would be unsuitable [1].
Q6Compare insertion sort and bubble sort. Give one similarity and two differences.[3]
✅ Mark scheme
Similarity (1): both O(n²) worst case / both in-place / both simple [1]. Differences (any 2): insertion sort shifts elements, bubble sort swaps adjacent pairs [1]; insertion sort is O(n) best case for sorted data, bubble sort O(n) only with swap flag [1]; insertion sort works better for nearly-sorted data [1].
Q7Explain what "in-place" means and state which of the four OCR J277 algorithms are in-place.[3]
✅ Mark scheme
In-place means the algorithm sorts/operates within the original data structure without creating a copy [1]. In-place: bubble sort, insertion sort [1]. NOT in-place: merge sort [1].
Q8For n = 1,000,000 items, calculate (approximately) the maximum number of operations for: (a) binary search (b) linear search[2]
✅ Mark scheme
(a) Binary search: log₂(1,000,000) ≈ 20 comparisons [1]. (b) Linear search: 1,000,000 comparisons [1].
?
out of 20 — self-mark above
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 10
Click to reveal definition
🎉
Complete!
TermDefinition
🎯

Mini Test — 2.1.3d Algorithm Comparison

10 questions · 10 marks · 10 minutes

← 2.1.3c Insertion Sort 2.1 Algorithms 2.1.3e Trace Tables →