OCR · GCSE · Computer Science

    Overview guide · Check your current course specification before revising.

    Efficiency and Complexity

    Unlock top marks in OCR GCSE Computer Science by mastering algorithm efficiency and complexity. This guide breaks down how to compare algorithms like an examiner, using Big O notation to analyse speed and scalability, ensuring you can justify why one search or sort is better than another.

    • 6 min read
    • 3 worked examples
    • 5 practice questions
    • 6 key terms

    Study Notes

    Overview

    Welcome to Topic 6.5: Efficiency and Complexity. In computer science, it's not enough to just write code that works; it must also be efficient. This topic explores how we measure and compare the performance of algorithms, a crucial skill for any programmer. We analyse how an algorithm's execution time and memory usage scale as the input data grows. Understanding this allows us to select the best algorithm for a given task, especially when dealing with large datasets where efficiency is paramount. For your exam, expect questions that require you to compare the efficiency of different search and sort algorithms, often using Big O notation. You will need to justify your choices, linking them to concepts like time complexity and space complexity, which are fundamental to building robust and scalable software.

    Key Concepts

    Concept 1: Computational Complexity

    Computational complexity is the measure of the resources (time and space) an algorithm consumes as the size of the input increases. Time complexity refers to the amount of time an algorithm takes to complete, while space complexity refers to the amount of memory (RAM) it requires. In your exam, time complexity is the more frequently tested concept. We use a formal system called Big O notation to classify algorithms based on how their resource usage grows. This provides a high-level understanding of their performance, allowing us to compare them in a standardised way.

    Example: An algorithm that checks every item in a list of size 'n' has a time complexity that grows linearly with 'n'. If the list doubles, the time taken roughly doubles. An algorithm that instantly finds an item regardless of list size has a constant time complexity.

    Concept 2: Big O Notation

    Big O notation is the standard way to express an algorithm's efficiency. It describes the worst-case scenario, giving an upper bound on how the execution time or memory usage will grow. For GCSE, you need to be familiar with the following classes:

    • O(1) - Constant Time: The algorithm takes the same amount of time regardless of the input size. This is the most efficient complexity class.
      • Example: Accessing an element in an array using its index.
    • O(log n) - Logarithmic Time: The time taken increases very slowly as the input size grows. The algorithm becomes more efficient per item as the dataset gets larger.
      • Example: Binary search.
    • O(n) - Linear Time: The time taken is directly proportional to the input size. If the input size doubles, the time taken doubles.
      • Example: Linear search.
    • O(n²) - Quadratic Time: The time taken is proportional to the square of the input size. This is inefficient for large datasets.
      • Example: Bubble sort.

    Comparison of algorithm complexity classes (Big O Notation)Open full-size image (opens in a new tab)

    Concept 3: Search Algorithms

    Searching is a fundamental operation. You need to know two key algorithms:

    • Linear Search: This algorithm sequentially checks each element in a list until the target value is found or the end of the list is reached. It is simple to implement and can be used on any list, sorted or unsorted. Its time complexity is O(n).
    • Binary Search: This is a much more efficient 'divide and conquer' algorithm, but it requires the list to be sorted. It works by repeatedly dividing the search interval in half. It compares the target value to the middle element; if they are not equal, the half in which the target cannot lie is eliminated, and the search continues on the remaining half. Its time complexity is O(log n).

    Visual comparison of Linear Search and Binary SearchOpen full-size image (opens in a new tab)

    Concept 4: Sorting Algorithms

    Sorting arranges items in a specific order. You need to understand the mechanics and efficiency of these algorithms:

    • Bubble Sort: This simple algorithm repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The passes through the list are repeated until the list is sorted. It is very inefficient for large lists, with a time complexity of O(n²).
    • Merge Sort: A more efficient 'divide and conquer' algorithm. It works by recursively splitting the list into halves until each sub-list contains a single element. Then, it merges the sub-lists back together in a sorted manner. Its time complexity is O(n log n), making it much faster than bubble sort for large datasets.
    • Insertion Sort: This algorithm builds the final sorted list one item at a time. It iterates through the input elements and inserts each element into its correct position in the sorted part of the list. It is efficient for small datasets or mostly sorted lists, with a worst-case time complexity of O(n²).

    Mathematical/Scientific Relationships

    Big O notation is the key mathematical relationship in this topic. It describes the growth rate of functions. While the underlying mathematics can be complex, for GCSE you only need to understand the relative performance of the key complexity classes.

    Big O NotationNamePerformance RankingMust Memorise
    O(1)Constant1 (Fastest)Must memorise
    O(log n)Logarithmic2Must memorise
    O(n)Linear3Must memorise
    O(n log n)Linearithmic4Must memorise
    O(n²)Quadratic5 (Slowest)Must memorise

    Practical Applications

    • Databases: When you search for a product on Amazon, efficient search algorithms are used to quickly find relevant items from millions of products. Databases often use highly optimised search and sort algorithms (like variants of B-Trees, which are related to binary search) to handle massive amounts of data.
    • Social Media: When your social media feed is generated, algorithms sort content based on relevance, recency, and your past interactions. The efficiency of these sorting algorithms directly impacts how quickly your feed loads.
    • GPS Navigation: Route-finding apps like Google Maps use complex graph algorithms (like Dijkstra's algorithm) to find the shortest path. The efficiency of these algorithms is critical for providing real-time directions.

    Check what you remember

    Read the wording for your board, then hide it and explain Algorithm in your own words. Rough notes are fine. This is a self-check, with no mark or grade.

    Reference: OCR

    A sequence of steps or a set of rules to be followed to solve a problem or perform a calculation, especially by a computer.
    OCR

    Interactive Diagrams

    2 interactive diagrams to visualise key concepts

    Conceptual Flow Outline

    Start
    ➔Is list sorted?
    Is list sorted?
    ➔NoPerform Linear Search O(n)
    ➔YesPerform Binary Search O(log n)
    Perform Linear Search O(n)
    ➔End
    Perform Binary Search O(log n)
    ➔End

    Flowchart showing the decision process for choosing between a linear and binary search based on whether the list is sorted.

    Conceptual Flow Outline

    n^2

    A Gantt chart illustrating the relative time taken by different complexity classes for a given input size. Note how Quadratic time is significantly longer.

    Worked Examples

    3 worked examples — open one to explore the question and available guidance.

    Practice Questions

    Try the question, then reveal an answer plan or example response

    Q1

    A programmer has a sorted list of 2 million song titles. They need to write an algorithm to quickly find if a specific song title exists. Which search algorithm should they use? Explain your choice. [3 marks]

    standard

    Hint: Consider the properties of the list (sorted, large) and the efficiencies of the search algorithms you know.

    Q2

    Explain what is meant by the term 'time complexity' in the context of algorithms. [2 marks]

    foundation

    Hint: Think about what changes as the input to an algorithm gets bigger.

    Q3

    A bubble sort algorithm is used to sort a list of 5 items. In the worst-case scenario, how many comparisons will the algorithm make on its first pass? [1 mark]

    foundation
    Q4

    Evaluate the use of bubble sort in a program that needs to sort a small, frequently updated list of high scores (around 10-15 scores). [4 marks]

    challenging

    Hint: Consider both the pros and cons of bubble sort. Is its main weakness (poor performance on large lists) relevant here?

    Q5

    Describe the steps a merge sort algorithm takes to sort a list. [5 marks]

    standard

    Hint: Think 'divide and conquer'. What are the two main phases?

    Ready to test yourself interactively?

    Active recall beats reading alone. Answer questions on Efficiency and Complexity with instant AI scoring and mark scheme guidance.

    Start interactive practice

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Exam technique

    How to turn what you know into marks

    How to approach the question

    1. **Identify the command word**: Is it 'Compare', 'Explain', or 'Evaluate'? This dictates the required depth. 2. **Spot the keywords**: Look for 'sorted', 'unsorted', 'large list', 'memory'. These are clues from the examiner. 3. **State the Big O**: Always start by identifying the complexity class of the algorithms involved. 4. **Explain the 'Why'**: Don't just state a fact (e.g., 'Binary search is faster'); explain *why* (e.g., 'because it halves the search space at each iteration').

    How to structure your answer

    For a **Compare** question (4-6 marks): Start with similarities (if any). Then, focus on differences, using comparative language ('whereas', 'on the other hand'). Discuss both time and space complexity. End with a concluding sentence that summarises which is better for the given scenario. For an **Explain** question (2-3 marks): Use the word 'because' to link your point to a reason. E.g., 'Algorithm X is inefficient *because* its time complexity is O(n²).'

    Timing

    Approximately 1 minute per mark, so a 6-mark question should take about 6-7 minutes

    Common pitfalls

    • Confusing O(log n) and O(n). Remember that logarithmic is much faster than linear for large lists.
    • Forgetting that binary search requires a sorted list. This is a classic mistake that loses easy marks.
    • Stating that bubble sort is 'useless'. It can be efficient for very small or nearly sorted lists, and its simplicity is an advantage.
    • Mixing up time and space complexity. Always be clear which one you are discussing.

    What the command words want

    Compare
    Identify similarities AND differences - use comparative language. E.g., 'Compare bubble sort and merge sort.'
    Explain
    Say HOW or WHY - use 'because' to link cause and effect. E.g., 'Explain why merge sort is efficient.'
    Describe
    Say what happens or what something is like. E.g., 'Describe how a linear search works.'
    Evaluate
    Consider both sides (pros and cons), use evidence (Big O), and make a supported judgement. E.g., 'Evaluate the use of binary search for this task.'
    Calculate
    Show working, use correct formula, include units. E.g., 'Calculate the estimated time.'
    State/Give
    Brief factual answer - 1-2 words or a short phrase. E.g., 'O(n²)'.

    Test your understanding of Efficiency and Complexity

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge