Big O Notation

Understand algorithm efficiency — visualize O(1), O(n), O(n²), O(log n) with interactive growth charts.

Category: Algorithms · v1.0.0
Step 1 of 6

Step 1: What is Big O?

Big O Notation describes the worst-case growth rate of an algorithm's time (or space) as the input size n increases. It does not measure exact time in seconds — it measures how the work scales.

Think of it this way: if you double the input, how much more work does the algorithm do?

Notation Name Example Growth
O(1) Constant Array index lookup Same speed regardless of n
O(log n) Logarithmic Binary search Doubles input, adds 1 step
O(n) Linear Loop through array Doubles input, doubles work
O(n log n) Linearithmic Merge sort Slightly worse than linear
O(n²) Quadratic Nested loops Doubles input, quadruples work
O(2n) Exponential Recursive Fibonacci Each +1 input doubles work

Analogy: Finding a Name in a Phone Book

Linear scan O(n) — Start at page 1, check every name one by one. With 1,000 pages, you might check all 1,000.

Binary search O(log n) — Open to the middle. Is the name before or after? Discard half. Repeat. With 1,000 pages, you need at most ~10 checks.

About This Lab

Big O Notation describes how an algorithm's performance scales with input size. In this lab, you'll visualize growth curves for common complexities, compare algorithms side by side, analyze code to determine its Big O, and develop intuition for writing efficient code.

How It Works

  1. Read each step's explanation of complexity concepts
  2. Interact with the growth curve visualizer
  3. Analyze code snippets for their Big O
  4. Compare algorithms at different input sizes
  5. Complete the quiz to test your understanding