ReviseAlgo Logo
MediumVery High Frequency30 min

DP Fundamentals

Memoization vs tabulation, overlapping subproblems, and optimal substructure.

DP = memoization of overlapping subproblems + optimal substructure. Identify state, recurrence, base case. Top-down = recursion + memo. Bottom-up = table filling.

Dynamic Programming

Operations — Step by Step

Climbing Stairs (1D DP)

O(n)O(1) space with two variables (prev1, prev2)
Step-by-step1 / 4
marker
0
0
marker
1
1
marker
2
2
marker
3
3
marker
5
4
marker
8
5

dp[1]=1, dp[2]=2 (base cases)

One way to reach stair 1 (1 step). Two ways to reach stair 2 (1+1 or 2).