Algorithm Learning/O(2^n) - Exponential Time

O(2^n) - Exponential Time

Learn O(2^n) through subsets. Cases explode 2x at each choice!

MediumComplexityExponentialSubsets

Definition

O(2^n) has 2 choices per element, creating 2^n cases. Each +1 to N doubles the time!

Key Characteristics

  • Doubles at each choice
  • N+1 → 2x time
  • N>30 is unmanageable

Use Cases

Used in these scenarios:

📦

Subset Generation

N elements → 2^N subsets

🐇

Recursive Fibonacci

Redundant calculation nightmare

🧩

Backtracking

Explore all cases

Complexity

Time Complexity

Best
O(2^n)
Average
O(2^n)
Worst
O(2^n)

Space Complexity

O(n)

Understand Deeper with Visualization

See how the algorithm works through step-by-step animations and code execution.

Start Visualization