Big O Notation
Understand algorithm efficiency — visualize O(1), O(n), O(n²), O(log n) with interactive growth charts.
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
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
More Labs in Algorithms
Recursion
AlgorithmsUnderstand recursive thinking through visual call stacks, step-by-step tracing, and interactive examples.
Sorting Algorithms Visualized
AlgorithmsWatch Bubble Sort, Selection Sort, and Insertion Sort in action with animated bar charts.
Graphs & BFS/DFS
AlgorithmsExplore graph data structures and traverse them with Breadth-First and Depth-First Search animations.