Learn in your language
Skip to content
A Level · Cambridge (CIE) · 9618

Time complexity

Describe how an algorithm's work grows as input size increases.

What you will learn

  • Recognise constant, linear and quadratic growth.
  • State assumptions when assigning a complexity.

Count growing operations

Time complexity describes the growth of work with input size n, rather than a stopwatch time on one computer. If an algorithm processes each item once using a bounded amount of work per item, its running time grows linearly.

Big-O gives an asymptotic upper bound. In common classroom comparisons, O(n) describes linear growth and O(n²) quadratic growth, but you should also state whether you are discussing the worst case, average case or another case.

Look inside loops

One loop over n elements is linear if its body takes constant time. Two nested loops each covering n elements can require n² body executions. Two separate loops over n elements require about 2n operations, which still has linear growth.

A loop that repeatedly halves a search range can have logarithmic growth, provided its other work does not dominate. Do not classify complexity from the number of visible loops alone.

Put the idea to work

Worked example

An algorithm scans a list of n values once to find the largest. Explain its worst-case time complexity.

Show the worked solution
  1. Each value is examined once.
  2. Each examination requires a bounded comparison and possible update.
  3. The number of operations grows in direct proportion to n.

Answer O(n)

Common mistakes

  • Two consecutive linear scans are O(n), not O(n²).
  • An expensive operation inside a loop can change its complexity.
Recall without your notes

What can you explain now?

Two nested loops each run n times and the inner body takes constant time. What is the growth?

Compare with the explanation

O(n²)

The inner body executes n times for each of n outer iterations.

After trying it yourself, choose your next review. This is your self-assessment.

Your review choice appears on Today. Sign in to sync it across devices.

Keep learning Computer Science

Course scope and assessment

This pathway maps the 2026 Version 2 and 2027–2029 Version 2 syllabuses, which Cambridge says have no significant changes affecting teaching. It has original teaching and guided, independent and transfer practice for all 20 syllabus sections, with topic links to the official section headings. It is mapped teaching, not proof of exam readiness or an official Cambridge grade. Paper 4 requires complete programs and testing evidence in a programming environment; the current course offers explained code and algorithm practice but does not yet provide a locked-down timed programming-paper environment, full four-paper mocks or human subject-teacher review.

StudyForA · Learn with understanding

Original teaching content and links to official sources. Check your exam year and qualification before using a resource.