LESSON 02 / 04

Big O Made Easy

Big O answers one question: when the input gets bigger, how much more work does my algorithm do? Learn O(1), O(log n), O(n), O(n log n) and O(n²) with everyday examples.

🎓Easylevel
⏱️40 minto finish
✏️4activities

📂 Big O & Problem Solving🏷️ Big O

🎯 By the end of this lesson you can…

  • Explain what Big O measures
  • Recognise the common complexity classes
  • Find the Big O of simple loops

How does the work grow?

The complexity ladder (for n = 1,000,000)
Big ONameEveryday exampleRough steps
O(1)constantlook up a locker by its number1
O(log n)logarithmicfind a word in a dictionary20
O(n)linearread every page of a book1,000,000
O(n log n)linearithmicsort a pile of exam papers well20,000,000
O(n²)quadraticcompare every student with every other1,000,000,000,000
O(2ⁿ)exponentialtry every combination of a lockway too many

Counting the work in code

⚡ JavaScript big-o-examples.js 👆 Tap a line to explain it
1function first(items) {2  return items[0];3}4function total(items) {5  let sum = 0;6  for (const x of items) sum += x;7  return sum;8}9function hasDuplicate(items) {10  for (let i = 0; i < items.length; i++) {11    for (let j = i + 1; j < items.length; j++) {12      if (items[i] === items[j]) return true;13    }14  }15  return false;16}17console.log(first([7, 8]), total([1, 2, 3]), hasDuplicate([3, 1, 3]));

Watch it grow

🐍 Python growth.py
1import math2print(f"{'n':>8} {'log n':>6} {'n log n':>10} {'n^2':>14}")3for n in [10, 100, 1000, 10000]:4    print(f"{n:>8} {round(math.log2(n)):>6} {round(n * math.log2(n)):>10} {n * n:>14}")

Three simplification rules

  1. Drop constants: O(3n) → O(n). We care about the shape of growth.
  2. Keep the biggest term: O(n² + n) → O(n²). For big n, n² dominates.
  3. Different inputs, different letters: looping over list a then list b is O(a + b), not O(n).
💡 Concept check
A loop runs n times and inside it another loop runs n times. What is the Big O?
💡 Concept check
What is O(5n + 100) simplified?
💡 Concept check
Binary search halves the list at each step. What is its complexity?
🛠️ Count the steps

Write pairs(n) that returns how many handshakes happen when n people each shake hands once with every other person — by actually counting with two nested loops. (Notice how fast the number grows!)

📌 Key takeaways

  • Big O describes how work grows as input grows — not exact seconds.
  • Drop constants and small terms: O(2n + 5) is O(n).
  • One loop over n items → O(n). A loop inside a loop → O(n²). Halving each step → O(log n).

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.