CS205

Growth Rate Visualization

See how different complexities grow as input size increases. Use the slider to explore different values of n.

Complexity Growth Comparison
0.020.0K40.0K60.0K80.0K100.0K020406080100Input Size (n)Operations
O(1) - Constant
O(log n) - Logarithmic
O(n) - Linear
O(n log n) - Linearithmic
O(n²) - Quadratic
O(2^n) - Exponential

Operations at n = 100:

O(1): 1.0
O(log n): 6.6
O(n): 100
O(n log n): 664
O(n²): 10.0K
O(2^n): 1.1B
Side-by-Side Comparison
Complexityn = 10n = 100n = 1.0Kn = 10.0K
O(1)Constant1.01.01.01.0
O(log n)Logarithmic3.36.610.013
O(n)Linear101001.0K10.0K
O(n log n)Linearithmic3366410.0K132.9K
O(n²)Quadratic10010.0K1.0M100.0M
O(2^n)Exponential1.0K1.1B1.1B1.1B

Notice how O(n²) and O(2^n) explode for large inputs. At n=1000, O(n²) is 1 million operations, while O(log n) is only about 10!

O(1)Constant Time

Operations take the same time regardless of input size

Growth pattern: Flat line - no growth
Common examples:
  • Array access by index
  • Arithmetic operations
  • Variable assignment
O(log n)Logarithmic Time

Operations grow slowly as input doubles

Growth pattern: Slow curve - grows very slowly
Common examples:
  • Binary search
  • Balanced tree operations
  • Loops that halve input
O(n)Linear Time

Operations grow proportionally with input size

Growth pattern: Straight line - proportional growth
Common examples:
  • Single loop through array
  • Linear search
  • Finding max/min
O(n log n)Linearithmic Time

Slightly worse than linear, common in efficient sorting

Growth pattern: Gentle curve - manageable growth
Common examples:
  • Merge Sort
  • Quick Sort (average)
  • Heap Sort
O(n²)Quadratic Time

Operations grow with the square of input size

Growth pattern: Steep curve - grows quickly
Common examples:
  • Nested loops
  • Bubble Sort
  • Comparing all pairs
O(2^n)Exponential Time

Operations double with each additional input

Growth pattern: Explosive - impractical for large inputs
Common examples:
  • Naive Fibonacci
  • Subset generation
  • Brute force combinations
Key Takeaways

Efficient: O(1), O(log n), O(n)

These scale well even for very large inputs. Binary search on 1 billion items takes only ~30 steps!

Moderate: O(n log n)

The sweet spot for sorting. Merge sort and quick sort use this complexity to efficiently sort large datasets.

Use with Caution: O(n²)

Nested loops are fine for small inputs (n < 1000), but become slow for larger datasets. Often can be optimized.

Avoid: O(2^n), O(n!)

Exponential algorithms only work for tiny inputs (n < 20). Beyond that, they become impractical.