Full Marks

A-level Computer Science Year 12 · Topic 2

Algorithms

Algorithms at A-level is about choosing and analysing efficient methods for searching, sorting and exploring data.

We will compare searches and sorts with big O notation, and add insertion sort and quick sort.

Then we traverse graphs and trees, find shortest paths with Dijkstra and A star, evaluate expressions in reverse Polish notation, and trace algorithms.

In this topic

  1. 2.1Searching, sorting and complexityFree below · 24 questions
  2. 2.2Insertion sort and quick sortOpen in Full Marks · 23 questions
  3. 2.3Graph and tree traversal: depth-first, breadth-first, pre-order, in-order and post-orderOpen in Full Marks · 25 questions
  4. 2.4Shortest path algorithms: Dijkstra's algorithm and A*Open in Full Marks · 20 questions
  5. 2.5Reverse Polish notation and expression evaluation using stacksOpen in Full Marks · 21 questions
  6. 2.6Representing and tracing algorithms: pseudocode, flowcharts and trace tablesOpen in Full Marks · 26 questions

2.1 · Free notes

Searching, sorting and complexity

Diagram: Searching, sorting and complexity

Key points

In more detail

Practice

Searching, sorting and complexity: 10 questions

Pick an answer to check it, or open the answer for the explanation.

1. What is the time complexity of binary search?

  1. O(1)
  2. O(log n)
  3. O(n)
  4. O(n²)
Show answer

B: O(log n). Each step halves the search space.

2. What is the time complexity of merge sort?

  1. O(n)
  2. O(log n)
  3. O(n log n)
  4. O(n²)
Show answer

C: O(n log n). Splitting gives log n levels, each requiring O(n) merging.

3. What does Big O notation describe?

  1. The exact run time in seconds
  2. How run time or space grows with input size
  3. The number of lines of code
  4. The memory address used
Show answer

B: How run time or space grows with input size. Constants and lower-order terms are ignored.

4. Which complexity is most efficient for large n?

  1. O(n²)
  2. O(n log n)
  3. O(2ⁿ)
  4. O(n!)
Show answer

B: O(n log n). O(n log n) grows far more slowly than the others listed.

5. What is the worst-case complexity of bubble sort?

  1. O(n)
  2. O(n log n)
  3. O(n²)
  4. O(1)
Show answer

C: O(n²). Nested passes over the list give quadratic growth.

6. What is the time complexity of accessing an array element by index?

  1. O(1)
  2. O(log n)
  3. O(n)
  4. O(n²)
Show answer

A: O(1). The address can be calculated directly.

7. Which sorting algorithm uses a divide-and-conquer approach?

  1. Bubble sort
  2. Insertion sort
  3. Merge sort
  4. Linear sort
Show answer

C: Merge sort. It splits, sorts and merges sublists.

8. Why is space complexity also important?

  1. It determines run time only
  2. Algorithms may need extra memory, which can be limited
  3. It has no impact
  4. It only matters for small inputs
Show answer

B: Algorithms may need extra memory, which can be limited. Merge sort, for example, needs extra storage.

9. A teacher must search an unsorted list of 500 names for one name. Which algorithm can be used directly without preparing the data?

  1. Merge sort
  2. Linear search
  3. Binary search
  4. Interpolation on the sorted list
Show answer

B: Linear search. Linear search checks each item in turn and needs no ordering. Binary search only works if the data is already sorted.

10. A sorted list of 1,000,000 items is searched with binary search. Approximately how many comparisons are needed at most?

  1. 500,000
  2. 20
  3. 1,000
  4. 1,000,000
Show answer

B: 20. Each comparison halves the search space, so about log₂(1,000,000) ≈ 20 comparisons are needed. 500,000 is the average for linear search.

Keep going in Full Marks

Full Marks has 24 questions on Searching, sorting and complexity (14 more than here), set out in practice levels. You also get notes and 3D models for all 6 subtopics of Algorithms, plus games, timed exams and past papers.

On your exam board

All A-level Computer Science Year 12 topics