Revision Notes
OxfordAQA IGCSE Computer Science (9210): Efficiency of algorithms – Revision Notes
Revision notes for OxfordAQA IGCSE Computer Science 9210 section 3.1.2: comparing time efficiency of algorithms by counting steps, early exit and a self-test.
- Subject
- Computer Science
- Level
- IGCSE
- Topic
- Topic 1 – Algorithms
- Author
- Marlbridge Academic Team
- Updated
- Reviewed by
- Harris Khan (what this means)
Aligned to OxfordAQA IGCSE Computer Science (9210), For teaching from September 2017, exams from May/June 2019. Official specification .
Syllabus page (what it covers and how it is assessed): OxfordAQA IGCSE Computer Science.
Syllabus points this page covers
9210
- 3.1.2 Efficiency of algorithms
This page covers 1 of the 4 subtopics in topic 1, Algorithms.
Found an error? Report a correction.
Need help with this topic? Request a free trial class for IGCSE Computer Science (9210).
Condensed notes for section 3.1.2 Efficiency of algorithms of OxfordAQA International GCSE Computer Science (9210). Worked examples are in the Efficiency of algorithms study guide.
What the specification asks
- Understand that more than one algorithm can be used to solve the same problem.
- Compare the efficiency of algorithms, explaining how some are more efficient than others for the same problem.
- Formal comparisons (such as Big O) are not required.
- Exam questions refer only to time efficiency.
Key ideas
| Idea | Meaning |
|---|---|
| Algorithm | A sequence of steps that completes a task |
| Time efficiency | How few steps (comparisons, assignments, loop passes) an algorithm needs to reach the answer |
| Early exit | Stopping as soon as the answer is known instead of finishing all the data |
| Efficient | Does less work than another algorithm that gives the same result |
Time efficiency is about the number of steps, not seconds. Seconds depend on the computer; steps do not.
Pairs of algorithms to know
| Problem | Algorithm 1 | Algorithm 2 | Why one does less work |
|---|---|---|---|
| Find an item | Linear search | Binary search | Binary search halves the sorted list each time |
| Sort a list | Bubble sort | Merge sort | Merge sort splits and merges, so needs fewer comparisons on large lists |
| Add 1 to 1,000 | Loop with 1,000 additions | n * (n + 1) DIV 2 |
The formula does the same 3 calculations whatever n is |
| Is n prime? | Test every divisor | Stop at the first divisor, and test only up to the square root | Fewer tests |
Counting steps: the numbers to remember
Searching for a value that is not in a sorted list:
| Items | Linear search | Binary search (at most) |
|---|---|---|
| 10 | 10 | 4 |
| 100 | 100 | 7 |
| 1,000 | 1,000 | 10 |
| 1,000,000 | 1,000,000 | 20 |
The gap is small for small lists and huge for large lists, so efficiency matters most for large amounts of data.
Prime test, counting divisions tested:
| n | Every divisor | Early exit | Early exit up to square root |
|---|---|---|---|
| 100 | 98 | 1 | 1 |
| 97 | 95 | 95 | 8 |
Early exit helps only when a divisor exists; for a prime the saving comes from stopping at the square root.
Bubble sort and early stopping
For the list 2, 1, 3, 4, 5, 6, 7, 8 a bubble sort with a fixed number of passes makes 28 comparisons. The version that stops when a pass makes no swaps makes 14 comparisons in 2 passes. Always say what work is avoided.
Where to look for inefficiency
- Work repeated that gives the same result each time.
- A loop that keeps going after the answer is found.
- Testing more items than necessary.
- A method that treats sorted data as if it were unsorted (such as linear search on a sorted list of a million items).
How to write a comparison answer
- Name both algorithms.
- State how each one works (the key difference).
- Give a number of steps for a stated amount of data.
- Conclude which is more efficient, and mention any condition (for example, the list must be sorted).
Sentence frame: “A is more efficient than B because it …, so for … items it needs about … steps rather than …”.
Model answer
Compare the efficiency of a linear search and a binary search of a sorted list of 1,000 items. [4 marks]
A linear search checks the items one at a time, so it may need up to 1,000 comparisons. A binary search compares the target with the middle item and discards half of the list each time, so it needs at most 10 comparisons. Binary search is therefore more time efficient for a large list. It can only be used if the list is sorted.
Notice the four ingredients: both algorithms named, the method of each, a number of steps for the same data, and a conclusion with its condition.
Exam traps
- Counting lines of code. Short code can still do a lot of work.
- “It is faster” with no reason. Always say why: fewer comparisons, fewer passes, earlier stopping.
- Talking about memory when the question says time. This specification only examines time efficiency.
- Faster computer, not better algorithm. A faster computer does the same steps more quickly; a better algorithm needs fewer steps.
- Forgetting conditions. Binary search is only more efficient if the data is sorted.
Key terms
| Term | Meaning |
|---|---|
| Comparison | Testing two values against each other, such as n MOD i = 0 or nums[i] > largest |
| Pass | One complete trip through the data or loop |
| Trade-off | Gaining one benefit at the cost of another, such as speed against needing sorted data |
Self-test
- State what is meant by time efficiency in 9210.
- Give two problems that have more than one algorithm.
- A list has 1,000 sorted items. State the most comparisons a binary search needs.
- State the number of comparisons a linear search needs in the worst case for the same list.
- Describe what an early exit is, with an example.
- Explain why a faster computer does not make an algorithm more efficient.
- Explain why
total ← n * (n + 1) DIV 2is more efficient than adding the numbers in a loop. - State one condition that must be true before a binary search is used.
- A bubble sort of 8 items without early stopping makes 28 comparisons. State why stopping after a pass with no swaps can save work.
- State whether you need Big O notation for this specification.
Answers:
- How few steps (such as comparisons) an algorithm needs to complete a task.
- Any two, such as searching (linear or binary) and sorting (bubble or merge).
-
- 1,000.
- Stopping as soon as the answer is known, such as a linear search stopping when the item is found.
- It runs the same number of steps, only more quickly. A more efficient algorithm needs fewer steps.
- The formula does a fixed number of calculations whatever the value of n, whereas the loop does one addition per number.
- The list must be sorted.
- If a pass makes no swaps, the list is already in order, so further passes are unnecessary.
- No. Formal comparisons are not required.
More resources on this topic
Related resources
-
Study guides
OxfordAQA IGCSE Computer Science (9210): Representing algorithms – Study Guide
Study guide to OxfordAQA IGCSE Computer Science 9210 section 3.1.1: algorithm, decomposition, abstraction, pseudocode, flowcharts, inputs, processing, outputs and trace tables.
Computer Science · OxfordAQA · IGCSE
Read guide -
Practice questions
OxfordAQA IGCSE Computer Science (9210): Representing algorithms – Practice Questions
Original OxfordAQA IGCSE Computer Science 9210 practice questions with answers on algorithms, decomposition, abstraction, pseudocode, trace tables and purpose.
Computer Science · OxfordAQA · IGCSE
Try questions -
Study guides
OxfordAQA IGCSE Computer Science (9210): Searching algorithms – Study Guide
Study guide to OxfordAQA IGCSE Computer Science 9210 section 3.1.3: linear search and iterative binary search, pseudocode, traces and a comparison.
Computer Science · OxfordAQA · IGCSE
Read guide
Get free revision emails (optional)
Occasional emails with practice questions, worked explanations and links to free resources for the qualification and subjects you choose. No spam, and you can unsubscribe from any email. The free tools on this site never need an email.