What is Big-O Notation?
Big-O notation describes how an algorithm's running time or memory use grows as the input size n grows, ignoring constants and lower-order terms. It lets programmers compare algorithms' worst-case efficiency at a glance.
Big-O notation, written O(f(n)), gives the upper bound on how an algorithm's cost scales with input size n. Common classes include O(1), O(log n), O(n), O(n log n) and O(n²), from fastest to slowest growth.
Try it: interactive calculator
Step-by-step worked examples
A loop runs once for every element in a list of 8 items. What's its Big-O?
1 pass, 8 comparisons, 1 operation per element T(n) = n → O(n) For n = 8, roughly 8 operations
Binary search on a sorted list of 1,024 items — how many steps at worst?
Each step halves the search space: 1024 → 512 → 256 → ... → 1 Number of halvings = log₂(1024) = 10 O(log n) → about 10 comparisons, not 1024
Nested loops, both running n times over a list of n = 6 items — how many operations?
Outer loop: 6 iterations Inner loop: 6 iterations each time Total = 6 × 6 = 36 operations T(n) = n² → O(n²)
Flashcards
Quick quiz
Q1.What does O(n) mean?
Q2.Binary search on a sorted array has what time complexity?
Q3.Which grows fastest as n increases?
Q4.Why is Big-O usually about the worst case?
The full card deck, worked steps and AI-tutor support for “What is Big-O Notation?” are in Notek — study by hand before your exam.
Common mistakes
Thinking Big-O measures exact running time in seconds. — Correct: Big-O measures how operations scale with input size, not actual clock time (which depends on hardware).
Believing O(2n) and O(n) are meaningfully different. — Correct: Constants are dropped in Big-O — both simplify to O(n) since growth trend is what matters.
Assuming O(n²) is always worse than O(n) for every input. — Correct: For small n an O(n²) algorithm can be faster in practice; Big-O only describes trends as n grows large.
Confusing Big-O (upper bound/worst case) with average-case complexity. — Correct: Big-O caps the worst case; some algorithms (like quicksort) have worse worst-case than average-case complexity.
FAQ
What is Big-O notation?
Big-O notation, O(f(n)), describes the upper bound on how an algorithm's running time or memory grows as input size n increases.
What is the formula for Big-O?
There's no single formula — instead, you express the dominant growth term, e.g., T(n) = 3n + 5 simplifies to O(n).
What are examples of Big-O notation?
O(1) constant (array lookup), O(log n) logarithmic (binary search), O(n) linear (single loop), and O(n²) quadratic (nested loops/bubble sort).
How do you calculate Big-O for an algorithm?
Count how operations scale with n, keep only the fastest-growing term, and drop constants — e.g., 2n² + 3n becomes O(n²).




