Counting: How do I get the number of bit strings of length n without always having to type all of them out?

252 Views Asked by At

enter image description here

Take these 2 questions as scenarios where I struggle to think logically on how to calculate these the non-tedious way.

For Q7)

I took n=6:

-X- -0- -X- -0- -X- -0- Here 0 is at even position fixed

Then I took the long approach of checking out each scenario where 101 doesn't occur, I got:

000000, 100010, 001000, 100000, 000010 = 5 strings

I did the same for, S0, S1, S2, S5, S4 and then got final answer D.

For Question 8)

I literally type out all 16 scenarios and get 0000, 0001, 1000 for n=4, same thing with n=3 and n=2. Then after all that I get the answer to be B. But again, there has to be an easier method that I just am not aware of or haven't thought of.

There has to be an easier way to count these? It takes way too much time to hand write this but I don't know what this method is.

Please can someone help me figure out a way to solve these types of problems the easier/ faster more logical way

1

There are 1 best solutions below

5
On BEST ANSWER

The idea is to think of how you make a string of length $n$ by starting with a shorter string and adding more characters. The challenge is to find a way that you can generate every string of length $n$ once and only once.

For 7 we can ignore all the zeros in even positions and ask the number of strings of length $\frac n2$ that do not contain $11$. That is asked and answered several times on this site and the answer is the Fibonacci sequence. If we want a string of length $n$ that does not include $11$, we can start with a string of length $n-1$ and append a $0$, which gets all the $n$ bit strings that end in $0$, or we can start with a string of length $n-2$ and append $01$, which gets all the legal $n$ bit strings that end in $1$. If $A(n)$ is the number of $n$ bit strings without $11$ we get $A(n)=A(n-1)+A(n-2)$, which is the Fibonacci recursion. Putting back in the zeros in your problem we have $S_n=S_{n-2}+S_{n-4}$.

For 8 to get an $n$ bit string you can start with $1$ and append an acceptable $n-1$ bit string, with $01$ and append an acceptable $n-2$ bit string, with $001$ and append an acceptable $n-3$ bit string, or with $000$ and append any $n-3$ bit string. I think the exponent on the $2$ should be $n-3$. That is supported by $S_3=1$ and $S_4=3$.