190k views
3 votes
There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a time. However, the person cannot climb 2 stairs after he or she has climbed 2 stairs in the last climb, which means the person cannot continuously climb 2 stairs. Let T(n) represent the number of ways the person can reach the top. Determine the recurrence that T(n)

User Kamath
by
7.6k points

1 Answer

4 votes

Final answer:

The recurrence relation for the number of ways to reach the top of n stairs without climbing 2 stairs consecutively, represented by T(n), is T(n) = T(n-1) + T(n-2), with base cases T(0) = 1 and T(1) = 1.

Step-by-step explanation:

The number of ways the person can reach the top of n stairs by climbing either 1 stair or 2 stairs at a time, without continuously climbing 2 stairs, can be represented by T(n). We need to establish a recurrence relation for T(n).

Let's consider two cases for how the person can reach step n:

  1. If the previous step was n-1, the person can only have gotten there by climbing 1 stair.
  2. If the previous step was n-2, the person can only have gotten there by climbing 1 stair as well, since they cannot climb 2 stairs consecutively.

Therefore, the total number of ways to reach step n is the sum of the number of ways to reach step n-1 and n-2. This establishes the recurrence relation:

T(n) = T(n-1) + T(n-2)

However, this recurrence relation assumes that T(0) = 1 (one way to stay at the bottom without climbing) and T(1) = 1 (one way to be on the first step).

User Thesmart
by
7.9k points