Skip to content
ExamSpine

B2.4 Programming algorithms: notes and practice

B2.4 covers standard algorithms and how efficient they are: linear and binary search, bubble and selection sort and Big O notation. At HL it adds recursion.

Paper 2Mixed14 practice questions

What you need to know

Our summary of the topic in our own words, not the IB guide. Points marked HL are for Higher Level only.

  • Explain what algorithmic efficiency means and why it is measured against input size rather than clock time
  • State the meaning of the common complexity classes including constant, linear, logarithmic and quadratic time
  • Determine the Big O complexity of a short piece of code from its loop structure
  • Distinguish best, average and worst case for an algorithm
  • Compare two algorithms for the same task on time and space and recommend one
  • Write a linear search and state its complexity
  • Write a binary search and explain why it requires sorted data
  • Trace a binary search on a given sorted list and count the comparisons
  • Write a bubble sort and state its complexity
  • Write a selection sort and state its complexity
  • Trace a sort pass by pass and give the list contents after each pass
  • Compare bubble and selection sort on time and space complexity and on number of swaps
  • Explain what recursion is and identify the base case and the recursive caseHL
  • Compare a recursive and an iterative solution to the same problem on clarity and costHL
  • Write a recursive algorithm for a standard problem such as factorial or FibonacciHL
  • Trace a recursive call stack and state the return valueHL

Learn it

Practice questions

Original questions written for the 2027 course, marked as you go. Easiest first.

Exam tips for B2.4

  • Binary search only works on sorted data. Say so whenever you use it.
  • Show the list after each pass when tracing a sort.
  • Work out Big O from the loops: one loop over n is linear, a loop inside a loop is usually quadratic.

Updated 24 October 2026. Topic codes are used as labels. Everything on this page is written by ExamSpine and is not endorsed by the IB.