How Many Ways Can You Climb n Stairs Using 2 or 3 at a Time?
At a glance
- 1. Define the count
Let a_n count routes to stair n when every move covers exactly 2 or 3 stairs.
- 2. Split by last move
A route ends with a 2-stair move or a 3-stair move, giving a_n = a_{n-2} + a_{n-3}.
- 3. Set initial values
Use a_0 = 1 for the empty route, and a_1 = 0 because one stair cannot be reached.
- 4. Count by move totals
For each possible number of 3-stair moves, count the arrangements of all 2- and 3-stair moves.
Suppose you climb a staircase of stairs, and each move must cover either 2 stairs or 3 stairs. The order of the moves matters: taking a 2-step move followed by a 3-step move is a different route from taking a 3-step move followed by a 2-step move.
Let be the number of valid routes to stair . The recurrence follows by sorting routes according to their final move. You can also get an explicit finite sum by choosing how many 3-step moves a route contains.
The recurrence and initial values
A route to stair must finish in one of two ways:
- Its last move covers 2 stairs, so the earlier part is a route to stair .
- Its last move covers 3 stairs, so the earlier part is a route to stair .
These two cases do not overlap, so for :
Use the following starting values:
The value counts the empty route: doing no moves is one way to reach the starting point. This convention makes the recurrence work at , giving . There is no route to stair 1, while stair 2 can be reached with one 2-stair move.
The first values are:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 1 | 2 | 2 | 3 | 4 |
An explicit formula using binomial coefficients
Suppose a route contains moves of 3 stairs. Those moves cover stairs, so the number of 2-stair moves must be
This is possible only when is nonnegative and even. Once the route has moves of 2 stairs and moves of 3 stairs, it contains moves in total. Choose which positions contain the 3-stair moves; the remaining positions are 2-stair moves. There are such arrangements.
Therefore,
This finite sum gives the count directly from , without generating all earlier values. For , the sum includes and gives , consistent with the empty-route convention.
Worked example: 8 stairs
For , the possible values of , the number of 3-stair moves, must make nonnegative and even. This leaves and .
- If , there are four 2-stair moves. They have one arrangement: .
- If , there is one 2-stair move and two 3-stair moves. The three moves can be ordered in ways.
Thus,
The four routes are , , , and .
Generating function and characteristic equation
The ordinary generating function is
The denominator records the permitted move lengths: after any partial route, the next move contributes either or . Equivalently, the recurrence has characteristic equation
If an exponential-root form is useful, let be the three roots of this equation. Then
The roots include a complex-conjugate pair, but their contributions combine to give the real integer count. The binomial sum is often the more practical explicit formula for this particular counting problem.
Common mistakes
- Allowing a 1-stair move: That is a different problem. If moves of 1, 2, or 3 stairs are allowed, the recurrence becomes , with different initial conditions.
- Counting move totals but not their order: A route with one 2-stair move and two 3-stair moves has three arrangements, not one.
- Using the wrong initial value at zero: Taking breaks the recurrence at . The empty route is counted as one way to cover zero stairs.
- Including impossible values of : In the sum, must be both nonnegative and even; otherwise the required number of 2-stair moves is not a nonnegative integer.
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.