Skip to content
Coding Interviews

Big O Notation Explained (No Math Degree Needed)

By The EbookWale Team · Updated June 16, 2026 · 5 min read

Big O notation describes how an algorithm's running time or memory grows as the input grows. A plain-English guide to O(1), O(log n), O(n), O(n log n) and O(n²) — with examples and a cheat sheet.

Big O notation describes how an algorithm’s running time or memory use grows as its input grows. It throws away constants and incidental details and keeps only the dominant term, so you can compare approaches by their shape — does the work stay flat, grow in a line, or explode?

It is the language interviewers use to ask “is your solution fast enough?”, and it is the difference between code that handles ten items and code that handles ten million. You do not need heavy math — you need to recognise a handful of growth patterns.

The core idea in three rules

  1. Count the work as a function of input size n. How many steps for n items?
  2. Keep only the fastest-growing term. n² + n becomes ; the smaller term is noise at scale.
  3. Drop constants. 3n and n/2 are both just O(n) — Big O cares about growth, not exact counts.

And by convention, Big O describes the worst case — the most work the algorithm could do — because that is what you must be able to survive.

O(n²) O(n) O(log n) O(1) input size n → operations
Big O is the shape of the curve as the input grows.
🔑 REMEMBER — Big O is about how the curve bends as n grows, not how many milliseconds something takes. A "slower" O(n) algorithm can beat an O(log n) one on tiny inputs — but for large n, the growth rate always wins.

The growth classes you must know

From fastest to slowest:

Big ONameDoubling the input…Example
O(1)Constant…changes nothingArray index arr[5], hash-map lookup
O(log n)Logarithmic…adds one stepBinary search in a sorted array
O(n)Linear…doubles the workA single loop over n items
O(n log n)Linearithmic…slightly more than doublesEfficient sorts (merge, quick, heap)
O(n²)Quadratic…quadruples the workNested loop over the same array
O(2ⁿ)Exponential…squares the workNaïve recursive Fibonacci, brute-forcing subsets
O(n!)Factorial…explodesGenerating every permutation

The jump from O(n log n) to O(n²) is the line most interview problems are fighting over: a brute-force double loop is O(n²), and the “good” answer usually uses a hash map or sorting to get to O(n) or O(n log n).

How to find the Big O of code

You can read it straight off the structure.

A single loop → O(n):

for (let i = 0; i < n; i++) {
  console.log(i);          // runs n times → O(n)
}

A nested loop over the same data → O(n²):

for (let i = 0; i < n; i++) {
  for (let j = 0; j < n; j++) {
    console.log(i, j);     // n × n → O(n²)
  }
}

Halving the problem each step → O(log n):

while (n > 1) {
  n = Math.floor(n / 2);   // 16 → 8 → 4 → 2 → 1 → O(log n)
}

Two separate loops → still O(n). O(n) + O(n) = O(2n) = O(n) — you drop the constant. Only nesting multiplies.

A quick heuristic: nested loops multiply, sequential loops add, halving is logarithmic, and a hash-map lookup is O(1).

Don’t forget space complexity

Big O also measures memory, using the same notation. An algorithm that builds a new array of size n uses O(n) space; one that swaps elements in place uses O(1). Interviewers often ask for both time and space, and the classic trade-off is “use more memory (a hash map) to save time” — turning an O(n²) search into O(n).

Recursion has a hidden space cost too: each pending call sits on the call stack, so deep recursion is O(depth) space even when it looks like it allocates nothing.

A data-structure cheat sheet

Big O is most useful when you know the cost of the operations you build on. Average-case costs:

OperationArrayHash mapBalanced BST
Access by indexO(1)
Search by valueO(n)O(1)O(log n)
Insert / deleteO(n)O(1)O(log n)

This is why “use a hash map” is the most common interview optimisation: it turns linear searches into constant-time lookups. We cover each structure’s trade-offs in The 8 data structures every developer should know.

Common mistakes

  • Confusing “fewer lines” with “faster.” A tidy nested loop is still O(n²). Structure determines Big O, not length.
  • Forgetting hidden loops. A .includes() or .indexOf() inside a loop is a loop inside a loop — secretly O(n²).
  • Ignoring space. A solution that is fast but allocates O(n²) memory can be just as disqualifying.
  • Optimising the wrong thing. For genuinely small, fixed inputs, O(n²) is fine. Big O matters when n can grow.
⚠️ GOTCHA — Calling array.includes(x) inside a for loop feels innocent but is O(n²). Swapping the array for a Set makes the lookup O(1) and the whole thing O(n) — a textbook interview fix.

Where this fits

Big O is the measuring stick for everything in coding interviewsdata structures, recursion, and the algorithm patterns built on them. Learn it first; every other topic refers back to it.

The full set — analysing loops, recursion costs, and the time/space trade-offs interviewers love — is worked through in our job-ready tier: JavaScript in Three Months, Python in Three Months, and Java in Three Months, each in the same diagram-first handwritten style. Aiming at senior or staff interviews, where the questions shift toward system design and subtler algorithmic trade-offs? The for Staff Engineers tier goes further: JavaScript, Python, and Java.

Once you can glance at code and name its Big O, interview problems stop being puzzles and start being a checklist.

Frequently asked questions

What is Big O notation in simple terms?

Big O notation describes how the work an algorithm does grows as its input gets bigger. It ignores constants and small details and focuses on the shape of that growth — so O(n) means the work grows in step with the input, and O(n²) means it grows with the square of the input.

Why do we drop constants in Big O?

Because Big O describes growth at scale, not exact timing. An algorithm that does 2n steps and one that does 5n steps both grow linearly, so both are O(n). As input gets large, constants and lower-order terms stop mattering compared to the dominant term.

Is O(log n) faster than O(n)?

Yes, much faster for large inputs. O(log n) means each step throws away a big fraction of the remaining work — like binary search halving the list each time — so doubling the input adds only one step. O(n) has to touch every element.

What Big O should I aim for?

It depends on the problem, but as a rule of thumb: O(1) and O(log n) are excellent, O(n) and O(n log n) are good and usually the target, O(n²) is acceptable for small inputs but a red flag in interviews for large ones, and O(2ⁿ) or O(n!) means you need a better approach.