Learn / Big O Notation

Intermediate 15 min

Big O Notation

Worst-case growth rates and comparing algorithms.

What you will learn

  • Read O(1), O(n), O(log n), O(n²)
  • Drop constants in big-O
  • Pick structure by operation cost

Big O describes how runtime or memory grows as input size n grows. We care about the dominant term, not whether you save 2Ɨ with a faster CPU.

Common complexities

O(1) — hash lookup. O(log n) — binary search. O(n) — scan an array. O(n log n) — good sorts. O(n²) — nested loops over n.

Try it yourself

What is the complexity of finding duplicates with nested loops vs a hash set?