Optimal Binary strings recursion

Not Understood this question, please explain.?

hello @CODER_JATIN
in this problem u need to tell the count of n length binary string which have no consecutive one.

for example if n=3
then all 3 length string are ->
000
001
010
011
100
101
110
111

total 8 , 3 length strings but 3 of them have consecutive ones(011,110,111) so we wont count them
hence our answer will be 5

okay and bhaiya is saying in this problem is f(n)=f(n-1)+f(n-2) ?? How is it working ?? Please EXplain?

case 1 -> if we place 1 at nth position then we cannot place 1 at n-1 th position right ? becuase that will give consecutive ones
therefore at n-1 we are allowed to place only 0
so because these two place are already reserverd
f(n)=f(n-2) // when 1 is placed at nth position

case 2 -> if we place 0 at nth position then
f(n)=f(n-1) // because there is no constraint on n-1th position

our answer will be summation of both the cases so
f(n)=f(n-2) + f(n-1)

Okay bhaiya, I’ll do and let you know if i face some problem :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.