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]
Implement a function getbits, that returns the(right adjusted) n bits that begin at position p of an integer. Assume bit position 0 is at the right end and that n and p are sensible positive values.
You are given n real numbers in an array. A number in the array is called a decimal dominant if it occurs more than n/10 times in the array. Give an O(n) time algorithm to determine if the given array has a decimal dominant.
Hint: use induction approach before reaching nth stair he can be either at n-1 or n-2 stairs.
ReplyDeleteSuppose 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)
@Hsingh you are right.The sequence generated is like fibonacci series.
ReplyDelete