CS concepts

Big-O Notation Explained in Plain English: 6 Speeds to Know

Updated Nov 27, 2026 · 5 min read

Big-O describes how the work an algorithm does grows as its input gets bigger, in the worst case, ignoring constant details. Six speeds cover most code: O(1) jumps straight there, O(log n) halves the problem each step, O(n) touches everything once, O(n log n) is sorting, O(n²) is a loop inside a loop, and O(2^n) is recursion that splits in two.

Watch onYouTubeInstagram

Key points

  • ●Big-O measures how work grows with input size, not seconds.
  • ●At 1 million items: O(1) is 1 step, O(log n) about 20, O(n) a million, O(n²) a trillion.
  • ●x in a set is O(1); x in a list is O(n).
  • ●Turning a nested loop into a set or dict lookup is the most common Big-O win.
  • ●Read the input size first: n up to about 20 allows 2^n, up to about 5,000 allows n², a million needs n log n or n.
Step-by-step visual sheet: Big-O in Plain English
The full visual sheet, made with Edithly.Open the interactive sheet

Same answer: a hundredth of a second, or 3 hours

Two pieces of code take the same input, a million items, and return the same answer. One finishes in about a hundredth of a second. The other takes almost 3 hours. The difference has a name: Big-O.

Big-O isn't seconds, because seconds depend on your laptop. It asks a simpler question: when the input gets bigger, how fast does the work grow? It looks at the worst case, not the lucky day where what you want is first in the list. And it ignores the small stuff: a step that takes 2 nanoseconds and one that takes 5 both count as one step. What matters is how many steps there are when n gets huge.

You only need six speeds. The visual sheet above shows all six at n = 1,000,000:

Speed Name Steps at 1 million Example
O(1) Constant 1 lst[5], dict lookup
O(log n) Logarithmic about 20 Binary search
O(n) Linear 1,000,000 One loop, x in list
O(n log n) about 20,000,000 sorted()
O(n²) Quadratic 1,000,000,000,000 Loop inside a loop
O(2^n) Exponential impossible Plain recursive stairs

O(1): constant time

The work doesn't change with the input. Ten items or ten million, it's one step. Reading lst[5] is O(1), because Python jumps straight to that slot. Looking up a key in a dict is O(1) on average, and so is checking whether something is in a set.

The trap: x in a_set is O(1), but x in a_list is not. Python checks every item one by one. Same two words, very different speed.

O(log n): throw away half

Every step throws away half of what's left. Think of a phone book: open it in the middle, decide which half your name is in, and repeat. A million names take about 20 steps. Double it to 2 million and it's 21. Doubling the input adds one step.

Binary search is the classic, and it even works on a rotated sorted array, where each loop still throws away a half. When a problem says "sorted" and wants better than a full scan, think log n. Heaps are log n too: heappush and heappop walk a tree that's only about 20 levels tall for a million items.

O(n): one pass

You touch every item once, so twice the input means twice the work. Finding the biggest number is O(n), because you can't know it's the biggest until you've seen them all.

A lot of O(n) hides inside one line of Python: sum, max, x in list, and copying a list with a slice. The one that catches people is pop(0). Taking the first item out of a list shifts every other item over, which is O(n) every time, so in a loop it quietly becomes O(n²). Use a deque and popleft(), which is O(1). Strings have the same trap, so collect pieces in a list and join once.

O(n log n): sorting

Python's sorted uses Timsort, which is O(n log n) in the worst case. At a million items that's about 20 million steps. Still fast.

It matters in interviews because if your idea needs the input sorted first, your answer can't beat O(n log n). Two pointers on a sorted array is O(n), but the sort costs O(n log n), so the whole thing is O(n log n), unless the list arrives already sorted. Merge Intervals is the same: sort by start time, then one pass to merge. Keep the bigger term.

O(n²): a loop inside a loop

Every item gets compared with every other item. Contains Duplicate asks whether any number appears twice. Checking every pair of a million items is a trillion steps, almost 3 hours even at 100 million steps a second.

The fix is to remember what you've seen in a set:

def contains_duplicate(nums):
    seen = set()
    for x in nums:
        if x in seen:
            return True
        seen.add(x)
    return False

One pass with O(1) checks makes it O(n): a hundredth of a second instead of 3 hours. That swap, a nested loop turned into a set or dict lookup, is the most common Big-O win in interviews. Watch for hidden ones too: a single loop that calls x in a_list or list.index inside it looks like one loop, but it's O(n²).

O(2^n): calls that split in two

Every step splits into two more, so adding one item doubles the work. Climbing Stairs asks how many ways you can reach the top taking one or two steps at a time. The plain recursive answer calls itself twice, ways(n - 1) + ways(n - 2), and for 40 stairs that's 331 million calls, because it solves the same small staircases again and again.

Fix it by remembering. Keep only the last two answers and walk up once:

def climb_stairs(n):
    a, b = 1, 1
    for _ in range(n - 1):
        a, b = b, a + b
    return b

Forty stairs now take about 40 steps. Some problems really are 2^n, like listing every subset: 20 items have about a million subsets, which is fine, but 30 items have over a billion. When you see subsets, check that n is small.

Space counts too

Big-O measures memory the same way. The seen set holds up to n items, so it's O(n) extra space. The stairs loop keeps only a and b, so it's O(1). Often you trade one for the other: the set bought speed with memory. Say that trade out loud in an interview.

Four rules for any code

  1. Drop the constants. 3n + 5 is O(n).
  2. Keep the biggest term. n² + n is O(n²).
  3. Loops one after another add. O(n) + O(n) is still O(n).
  4. Loops inside loops multiply. n × n is n².

So a sort followed by a loop is n log n + n, which is O(n log n). And if the work halves every step, there's a log in it.

Read the input size first

The constraints tell you how fast the answer must be:

  • n up to about 20: O(2^n) is fine, about a million options.
  • n up to about 5,000: O(n²) works, about 25 million steps.
  • n up to 100,000 or 1,000,000: you need O(n log n) or O(n). A nested loop will time out.

Quick quiz

  • Is a word in a set of a million words? O(1).
  • Find a name in a sorted list of a million? O(log n), about 20 steps.
  • Every pair from 500 students? O(n²), and that's fine: about 125,000 pairs. n² only hurts when n is big.

In one breath: O(1) jumps straight there, log n throws away half, O(n) touches everything once, n log n is sorting, n² is a loop inside a loop (fix it with a set), and 2^n is calls that split in two (fix it by remembering answers).

Frequently asked questions

What is Big-O notation in simple terms?

It answers one question: when the input gets bigger, how fast does the work grow? It ignores your laptop's speed and small constant costs, and it describes the worst case, not the lucky one.

What is the Big-O of x in a list in Python?

O(n). Python checks the items one by one until it finds x or reaches the end. The same check on a set or a dict key is O(1) on average.

Is O(n log n) much slower than O(n)?

Not much. At 1 million items, O(n) is about 1 million steps and O(n log n) is about 20 million, roughly 20 passes. Both are fast. O(n²) at the same size is a trillion steps, almost 3 hours.

How do I know which Big-O a problem needs?

Read the constraints. If n is at most about 20, O(2^n) is fine. Up to about 5,000, O(n²) works. If n reaches 100,000 or 1 million, you need O(n log n) or O(n).

Turn any problem or document into a visual sheet like this one

Paste a LeetCode problem, a PDF or a link into Edithly and get a step-by-step sheet you can study, share or quiz yourself on.

Make this sheet in Edithly, free