How do we measure and compare the efficiency of algorithms using Big-O notation?
Big-O notation for time and space complexity: the constant, logarithmic, linear, linearithmic, polynomial and exponential complexity classes, how to determine the Big-O of an algorithm, and using it to compare and judge the suitability of algorithms.
An OCR H446 answer on Big-O notation: the constant, logarithmic, linear, linearithmic, polynomial and exponential complexity classes for time and space, how to determine an algorithm's Big-O, and using it to compare algorithms and judge their suitability.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
OCR wants the meaning of Big-O for time and space, the standard complexity classes in order, how to determine an algorithm's Big-O (from loops and recursion), and how to use Big-O to compare algorithms and judge suitability. This is analysis: expect to order classes, give examples, and determine the complexity of a code fragment.
The answer
What Big-O measures
Why constants and lower-order terms are dropped
The complexity classes and determining Big-O
Examples in context
Choosing binary search () over linear search () is the difference between 20 and a million comparisons on a million items. Quadratic sorts become unusable on large datasets, so libraries use sorts. Exponential algorithms (naive travelling salesman) are why heuristics exist. Database query planners reason about complexity to pick efficient strategies. OCR ties Big-O to the searching, sorting and graph algorithms (each labelled with its complexity) and to the computational methods that tame intractable problems.
Try this
Q1. State what Big-O notation describes. [1 mark]
- Cue. How an algorithm's running time (or space) grows as the input size grows (its worst-case order of growth).
Q2. Give the time complexity of an algorithm with a single loop running times, and one with two such loops nested. [2 marks]
- Cue. Single loop ; nested loops .
Q3. Order , , and from most to least efficient. [1 mark]
- Cue. , , , .
Exam-style practice questions
Practice questions written in the style of OCR exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
OCR 20206 marksOrder the complexity classes , , , and from most to least efficient for large , and give an example algorithm for three of them.Show worked answer →
Ordering (up to 3), most efficient first: , , , , . (Constant beats logarithmic beats linear beats quadratic beats exponential.)
Examples (up to 3), any three: accessing an array element by index; binary search; linear search; bubble or insertion sort; a naive recursive solution to the subset/travelling-salesman-style problem. Markers reward the correct efficiency order and valid example algorithms. A common error is ranking as better than incorrectly, or vice versa; exponential is the worst.
OCR 20226 marksExplain what Big-O notation describes, why constants and lower-order terms are dropped, and determine the time complexity of an algorithm that contains a single loop nested inside another loop, each running times.Show worked answer →
What Big-O describes (up to 2): Big-O describes how an algorithm's running time (or space) grows as the size of the input grows, giving the worst-case order of growth so algorithms can be compared independently of hardware.
Dropping constants and lower-order terms (up to 2): for large the fastest-growing term dominates, so constant factors and lower-order terms become insignificant; is written because the term dominates. This captures scalability, not exact timings.
Nested loops (up to 2): a loop running times with another loop running times inside it performs about operations, so the time complexity is . Markers reward growth-with-input-size, dominance of the highest-order term, and for the nested loops.
Related dot points
- Searching algorithms: linear search, binary search and binary tree search, how each works with a trace, the precondition for binary search, and their time complexity in Big-O notation.
An OCR H446 answer on searching algorithms: how linear search, binary search and binary tree search work with worked traces, the requirement that binary search needs a sorted list, and the time complexity of each in Big-O notation.
- Sorting algorithms: bubble sort, insertion sort, merge sort and quick sort, how each works with a trace, and their time complexity in Big-O notation including best, average and worst cases.
An OCR H446 answer on sorting algorithms: how bubble sort, insertion sort, merge sort and quick sort order a list with worked traces, and their time complexity in Big-O notation including the difference between the quadratic and the divide-and-conquer sorts.
- Graph and tree traversal: breadth-first and depth-first traversal of a graph, the pre-order, in-order and post-order traversal of a binary tree, and the shortest-path algorithms Dijkstra's algorithm and A* search.
An OCR H446 answer on traversal and shortest-path algorithms: breadth-first and depth-first graph traversal, the pre-order, in-order and post-order traversal of a binary tree, and how Dijkstra's algorithm and A* search find a shortest path.
- Thinking logically: identifying the decision points and conditions that affect the flow of a solution; computational methods including problem recognition, divide and conquer, backtracking, heuristics, performance modelling and visualisation.
An OCR H446 answer on thinking logically and computational methods: identifying decision points and conditions in a solution, and the methods of problem recognition, divide and conquer, backtracking, heuristics, performance modelling and visualisation that make problems solvable.
- Mathematical skills for computer science: set theory and set operations, the comparison of binary, denary and hexadecimal magnitudes, simple logic propositions, and the use of these tools to reason about data and algorithms.
An OCR H446 answer on the mathematical skills underpinning computer science: set theory and set operations, comparing magnitudes across binary, denary and hexadecimal, simple logic propositions, and applying these tools to reason about data and algorithms.