AlgoViz

Fibonacci

Calculate Fibonacci numbers efficiently using dynamic programming with memoization to avoid redundant calculations.

BeginnerTime: O(n)Space: O(n)
Take Quiz
Step 1 / 0

Current Step

Click Play to start the visualization


## How Fibonacci with DP Works

The Fibonacci sequence is a classic example for demonstrating dynamic programming. Instead of redundant recursive calls, we store computed values.

### Algorithm Steps (Bottom-Up):
1. Initialize base cases: F(0) = 0, F(1) = 1
2. For each n from 2 to target:
- Calculate F(n) = F(n-1) + F(n-2)
- Store result in memoization table
3. Return F(target)

### Key Characteristics:
- **Memoization**: Store computed values to avoid recalculation
- **Optimal Substructure**: F(n) depends on F(n-1) and F(n-2)
- **Overlapping Subproblems**: Same subproblems solved multiple times in naive recursion

Time & Space Complexity

CaseTime Complexity
BestO(n)
AverageO(n)
WorstO(n)
SpaceO(n)

Practice Problems

10 problems81 total points
1

Nth Fibonacci Number

Beginner5 pts
2

Climbing Stairs

Beginner5 pts
3

Tribonacci Number

Beginner5 pts
4

Min Cost Climbing Stairs

Intermediate8 pts
5

House Robber

Intermediate8 pts
6

House Robber II

Advanced10 pts
7

Decode Ways

Advanced10 pts
8

Perfect Squares

Advanced10 pts
9

Unique Binary Search Trees

Advanced10 pts
10

Knight Dialer

Advanced10 pts