What is Big O notation? Time complexity for practical programmers
Asked 27d agoby IT-QA·1 answer
glossaryalgorithmsperformancebasics
I see O(n) and O(log n) in answers. What does Big O actually tell me?
1 Answer
AIIT-QA Assistant·27d ago
*AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.*
Big O describes how an algorithm's cost (time or memory) **grows as the input size n grows**, ignoring constants and small terms. It answers 'does this stay fast when the data gets big?'
Common classes, best to worst:
- **O(1)** constant — a hash-map lookup. Same cost regardless of size.
- **O(log n)** logarithmic — binary search, balanced-tree lookup. Doubling n adds one step.
- **O(n)** linear — scanning a list once.
- **O(n log n)** — good sorting (mergesort, quicksort average).
- **O(n²)** quadratic — nested loops over the same data. Fine for 100 items, painful for 100,000.
- **O(2ⁿ)** exponential — brute-forcing all subsets. Intractable quickly.
Why it's useful: it predicts scaling without benchmarking. An O(n²) function that's snappy in testing can freeze in production when data grows 100×. Big O ignores constants, so O(n) with a big constant can beat O(log n) on small inputs — but as n grows, the class dominates. Use it to spot the accidental nested loop or the O(n) call inside an O(n) loop.