Linear algebra and discrete math · University

Complexity O(n)

O(n log n)

The idea

“Big O” tells you how fast the work grows as the data grows.

The board

  1. O(1) — always the same time (take the first element).
  2. O(n) — proportional (read them all).
  3. O(log n) — searching a sorted dictionary: you halve it every time.
  4. O(n2) — compare everyone with everyone. With a million items — a trillion steps.

The most common mistake

Thinking O counts seconds. It counts how the work grows — constants are ignored.

The trick

Binary search in 1 billion sorted names: only ~30 steps, because log2 109 ≈ 30.

Problems

Which is fastest for huge data?

  • O(log n)
  • O(n)
  • O(n²)
  • O(2ⁿ)
Show the answer

O(log n) — The logarithm grows slowest.

Comparing everyone with everyone is…

  • O(log n)
  • O(1)
  • O(n)
  • O(n²)
Show the answer

O(n²) — n · n.

Take the lesson · exercises and XPFree, no sign-up needed.

You need to know