A rabbit sits at the bottom of a staircase with n stairs.rabbit can hop up only one or two stairs at a time.how many different ways are there two reach at top of stair.
Suppose W(n) different ways are there two reach at top of stair.
Now W(1) = 1 [It can be done by a single step only] W(2) = 2 [It can be done by taking two stairs at one time or 2 steps of one stair]
W(3) = W(2) + W(1) [1st reach upto stair #1 and then move to stair #3 by taking double step or 1st reach upto stair #2 and then move to stair #3 by taking single step]
Suppose W(n) different ways are there two reach at top of stair.
ReplyDeleteNow
W(1) = 1 [It can be done by a single step only]
W(2) = 2 [It can be done by taking two stairs at one time or 2 steps of one stair]
W(3) = W(2) + W(1) [1st reach upto stair #1 and then move to stair #3 by taking double step or
1st reach upto stair #2 and then move to stair #3 by taking single step]
Similarly W(n) = W(n-1) + W(n-2)
This looks line Fibonacci series
ReplyDelete