Coutn_of_binary_strings problem

sir i mnot able to understand the top down approach of this question plz share the code.

hi anuj
his problem can be solved using Dynamic Programming. Let a[i] be the number of binary strings of length i which do not contain any two consecutive 1’s and which end in 0. Similarly, let b[i] be the number of such strings which end in 1. We can append either 0 or 1 to a string ending in 0, but we can only append 0 to a string ending in 1. This yields the recurrence relation:

a[i] = a[i - 1] + b[i - 1]
b[i] = a[i - 1]
The base cases of above recurrence are a[1] = b[1] = 1. The total number of strings of length i is just a[i] + b[i].
And another interesting hack of the problem is the number of binary strings are related to some fibbonacci sequence as well.
the count is actually (n+2)’th Fibonacci number for n >= 1.

But sir this is bottom up approach.

i want top down approach how can i do with the help of recurssion

you can refer this

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.