Complexity O(n)
O(n log n)
The idea
“Big O” tells you how fast the work grows as the data grows.The board
- O(1) — always the same time (take the first element).
- O(n) — proportional (read them all).
- O(log n) — searching a sorted dictionary: you halve it every time.
- 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.