TutorChase logo
Login
AQA A-Level Computer Science

13.4.3 Order of complexity

Understanding the order of complexity helps us analyse how efficiently an algorithm runs as its input size grows, using Big-O notation to compare performance.

What is Big-O notation?

Big-O notation is a mathematical tool used to describe the efficiency of an algorithm as the size of the input increases. It allows us to express how execution time or space requirements grow without getting bogged down by specific hardware, programming languages, or implementation details.

Big-O notation focuses on the worst-case scenario, meaning it shows the maximum time or space an algorithm might need. This is especially useful when evaluating performance guarantees for large inputs. It provides an abstract way to compare the scalability of different algorithms.

For example, if one sorting algorithm takes O(n log n) time and another takes O(n²) time, the first will usually be more efficient, especially for larger input sizes.

Key characteristics of Big-O:

  • Ignores lower-order terms (e.g. O(n² + n) becomes O(n²)).

  • Ignores constant factors (e.g. O(3n) becomes O(n)).

  • Focuses on how the algorithm grows with input size, n.

Common orders of time complexity

Take your grades to the next level!

UPGRADING TO PREMIUM UNLOCKS
AI Tutor
AI-powered study assistant
instant feedback and guidance
Predicted Papers
Examiner-style predicted papers
based on recent exam trends
Practice Questions
All exam practice questions
by topic for each subject
Study Notes
All detailed revision notes
written by expert teachers
Cheat Sheets
Quick revision summaries
perfect for last-minute review
Past Papers
Complete collection
of practice and past exam papers
Email
Password
Confirm Password
Already have an account?

Practice Questions

FAQ

In Big-O notation, constants and lower-order terms are ignored because Big-O is concerned with how an algorithm’s performance scales as input size becomes very large. Constants (like 3n or 5n) only affect execution time by a fixed multiplier, which is negligible compared to the rate of growth. For example, both O(3n) and O(n) grow linearly, and the multiplier “3” has little impact for sufficiently large n. Similarly, lower-order terms such as n in O(n² + n) become insignificant when n is large, as n² will dominate the overall growth. Big-O captures the dominant term because it reflects the true nature of how an algorithm behaves as data scales. This simplification allows us to compare algorithms more effectively, focusing on structural differences rather than implementation details. The goal is to understand algorithm efficiency in the long term, especially when dealing with inputs in the thousands or millions.

The ‘worst-case’ scenario in Big-O refers to the maximum amount of time or space an algorithm could possibly take, given any valid input of size n. It is used because it provides a guaranteed upper limit on performance, ensuring that the algorithm won’t exceed this bound regardless of the input. This is crucial in critical systems such as banking or healthcare where unpredictable delays could be harmful. Worst-case analysis gives developers and system architects confidence that their algorithms won’t fail or hang under the most demanding conditions. While average or best-case complexities can be useful in some contexts, they rely on assumptions about input distributions or specific patterns that may not always be present. Worst-case Big-O analysis is safer and more robust, especially when designing systems for reliability and responsiveness. It ensures that even if input is adversarial or unexpected, performance remains within acceptable limits.

Time complexity and space complexity are both measured using Big-O notation, but they focus on different resources. Time complexity refers to how the execution time of an algorithm grows as the input size increases. It’s about the number of steps or operations the algorithm performs. On the other hand, space complexity measures how much memory or storage the algorithm uses in relation to input size. This includes memory used for input storage, output storage, variables, function calls, and recursion stack. For instance, a sorting algorithm like bubble sort has a time complexity of O(n²) and space complexity of O(1) since it doesn’t use extra memory beyond the input array. Merge sort, however, has a better time complexity of O(n log n) but worse space complexity of O(n) due to additional arrays used in the process. In Big-O terms, both time and space are expressed similarly but describe fundamentally different performance characteristics.

Yes, an algorithm can involve multiple stages, each with different Big-O complexities, and in such cases, we focus on the dominant stage—the part of the algorithm with the highest growth rate as n increases. For example, an algorithm might perform a linear scan to prepare data (O(n)) and then use a nested loop to process it (O(n²)). While both operations matter, the overall time complexity is O(n²) because it dominates the performance as n becomes large. Additionally, conditional operations or branching might cause different paths through the code to have different complexities. In such situations, we still express the algorithm’s complexity in terms of the worst-case path. It’s also possible for recursive functions to have a linear stage and an exponential recursive step; again, the most expensive part dictates the overall complexity. Analysing an algorithm involves identifying each part and understanding how they combine, but the final Big-O expression only includes the dominant term.

When an algorithm operates on multiple inputs with different sizes—say, arrays of size n and m—the time complexity must reflect both variables. In such cases, we use Big-O notation with multiple terms, like O(n * m), where n and m represent the sizes of the separate inputs. For example, if an algorithm compares every item in list A with every item in list B, the total number of operations would be proportional to n × m. This approach allows us to analyse complexity more accurately when inputs are not of the same length or type. We do not combine the variables unless they are guaranteed to be of the same size. In some cases, you might see complexities like O(n + m) when the algorithm processes both inputs independently. It is essential to keep the terms separate unless the problem clearly defines a relationship between the inputs. Multi-variable Big-O helps evaluate scalability across diverse datasets.

Hire a tutor

Please fill out the form and we'll find a tutor for you.

1/2
Your details
Alternatively contact us via
WhatsApp, Phone Call, or Email