OCR A-level Big O notation: what is the time complexity?

OCR-style pseudocode
total = 0
for i = 0 to n - 1
    total = total + scores[i]
next i
print(total)

What is the time complexity, as the tightest Big O?

Question 1 of 8

Pick an answer

Your result

A-level Computer Science Pro

Get an A or your money back

£119 once

Price rises to £199 on 1 January. Save £80 by joining before then.

By paying you agree to our Terms and get access straight away, which ends your 14-day cancellation right.

No VAT is charged. Conditions

The OCR A-level Big O notation drill has 8 practice questions, each with a worked answer.

Questions people ask

How do you work out Big O from code?

Find the line that runs most often and count its runs in terms of n. One loop is O(n), a loop inside a loop is O(n²), halving each time is O(log n).

Why is two loops one after another O(n)?

n + n = 2n steps, and Big O drops constant multiples, so it is O(n). Only a loop inside a loop multiplies.

What Big O does OCR expect you to know?

Constant O(1), logarithmic O(log n), linear O(n), polynomial such as O(n²), and exponential O(2ⁿ), plus the complexities of the standard searching and sorting algorithms.

How we work this out

What it does

Read the code, pick its Big O, and see how to count the steps.

OCR A Level Computer Science (H446) 2.3.1: Big O time complexity of code fragments.

Method

  1. Count how many times the innermost line runs as n grows, then keep the fastest-growing term and drop constants.
  2. Each wrong choice is a common slip: one loop counted as two, a halving loop counted as linear, or a constant left in.

Independent practice for OCR A-level Computer Science (H446), not endorsed by OCR.

Privacy · Terms