Choose Complexity Class
Input Size: 10
Execution Trace
Pseudocode
Statistics
Operations
0
Complexity
O(1)
Formula
f(n) = 1
Step Progress
0 / 0
Master Big-O notation and analyze algorithm efficiency. Understand how code scales with input size. Visualize and compare time complexities of common algorithms and data structures.
Time complexity measures how runtime changes as input size increases. It depends on two things:
O(1) — Constant: No loops, direct accessO(log n) — Logarithmic: Halve the search space each iterationO(n) — Linear: Single loop through all elementsO(n log n) — Linearithmic: Loop + logarithmic operation per iterationO(n²) — Quadratic: Nested loopsO(2ⁿ) — Exponential: Each step doubles the workInteractive Complexity Visualizer
Choose Complexity Class
Input Size: 10
Execution Trace
Pseudocode
Statistics
Operations
0
Complexity
O(1)
Formula
f(n) = 1
Step Progress
0 / 0
Complexity Growth Comparison
How Complexity Scales With Input Size
| O(1) | 1 |
| O(log n) | 4 |
| O(n) | 10 |
| O(n log n) | 34 |
| O(n²) | 100 |
| O(2ⁿ) | 1,024 |
Notice: Each complexity class creates dramatically different operation counts!
Understanding Loop Patterns
| Pattern | Code Example | Complexity | Reason |
|---|---|---|---|
| Halving Loop | n = n / 2 each iteration |
O(log n) | Range halves each step (log₂ steps needed) |
| Single Loop | for i in 0..n |
O(n) | Loop runs n times |
| Loop + Halving | for each, halve remaining |
O(n log n) | n iterations × log n work each = n log n |
| Nested Loops | for i in 0..n: for j in 0..n |
O(n²) | n × n iterations = n² total |
Key Concepts
Halving Pattern
n → n/2 → n/4 → ... = log n steps
Single Loop
Loop runs n times = O(n)
Nested Loops
Loop inside loop = n × n = O(n²)
Loop + Halving
n iterations × log n work = O(n log n)
Scalability
O(n) processes 1M items. O(n²) takes 1M² times longer!
Choose Wisely
Algorithm choice dramatically impacts performance
Understand Loops
Master loop patterns = master complexity analysis