AlgoScope

Climbing Stairs

Ways to reach step n = ways(n-1) + ways(n-2).

Dynamic programming, algorithm, beginner
Index 2 is 1 plus 1, which is 2.101122345678i
Index 2 is 1 plus 1, which is 2.101122345678i

DP in One Row: Ways to climb 8 stairs

Decision, step 2 of 9

dp[2] = dp[1] + dp[0] = 1 + 1 = 2.

How dp in one row works

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(1)

Leads to

Topics that need this one first.

Taught by the same lesson

DP in One Row covers these too, in the same run.