9

How many bit strings of length 10 contain either five consecutive 0's or five consecutive 1's ?

My Solution:

for 5 consecutive 0's

After we have filled 0's from $1^{st}$ position we have 2 choices each for the rest 5 positions After we have filled 0's from $2^{nd}$ position we have 2 choices each for the rest 5 positions $\dots$ After we have filled 0's from $6^{th}$ position we have 2 choices each for the rest 5 positions

making it total $6 \times 2^{5}$

Now, for 5 consecutive 1's

After we have filled 1's from $1^{st}$ position we have 2 choices each for the rest 5 positions After we have filled 1's from $2^{nd}$ position we have 2 choices each for the rest 5 positions $\dots$ After we have filled 1's from $5^{th}$ position we have 2 choices each for the rest 5 positions

making it total $4 \times 2^{5}$

Becasue 1111100000 and 0000011111 is already counted above

So making a total of $(6+4) \times 2^{5}=10 \times 2^5$

Please correct me If I've done something wrong

Atinesh
  • 1,239

2 Answers2

9

The problem with your approach is that you are counting some arrangements more than once. Eg when you count by grouping and summing, you must take care that the groups are exclusive. For example, you count:

00000***** $\to 2^5$

*00000**** $\to 2^5$

but a configuration like 0000001111 belongs to both groups, hence you are couting it twice. And some, more than twice (eg, 0000000111 belongs to three groups).

To count the strings of 10 bits with at least 5 consecutive zeros, lets group them according to $k=$ the first zero position in the (possibly larger than 5) run. Then $k\in \{1,2,3,4,5,6\}$ (counting from one).

For $k=1$, we have $2^5$ strings: ( 00000*****)

For $k>1$ , we have $2^4$ strings (eg *100000*** for $k=3$)

This groping is exhaustive and exclusive. Hence the number of strings with at least 5 consecutive zeros is $ 2^5 + 5 \times 2^4 = 112$

By symmetry, the number of strings with at least 5 consecutive ones is the same; however, this would count both 0000011111 and 1111100000 twice (as you noticed), hence the total number is

$$112 + 112 -2 = 222$$

Notice that this method only works because of $\ell \ge n/2$ ($\ell$ is the runlength, $n$ the total length) , otherwise more complicated methods would be needed (example).

Learner
  • 13
leonbloy
  • 63,430
1

You have double counted a lot of strings that have more than the required number of consecutive identical digits.

The problem is symmetrical between 0s and 1s, and you have correctly identified the only 2 cases of double counting between the "consecutive 0s" and the "consecutive 1s" cases, although you have used that to wrongly restrict the 1s case. So let's just look at consecutive 0s for now.

I agree with $6\cdot 2^5$ for the first step, but we need to deal with the over-count. We need to subtract out the double counted 6(+)-consecutive cases of which there are $5\cdot 2^4$ by the same logic. The 6-consecutive-zero strings also overcount, but in any one string by exactly 1 less than the 5-consecutive-zero strings. Therefore this identifies all the overcount so the final total for 5-consecutive-zero cases is $$6\cdot 2^5 - 5\cdot 2^4 = 112$$

So we also get 112 for counting purely 5 consecutive-1 strings, and for the combination we subtract the 2 cases that qualify for both 5 1s and 5 0s: $$112+112-2 = 222 $$

Joffan
  • 39,627
  • 1
    "we need to subtract out the double counted 6-consecutive cases" that means "at least 6-consecutive, no?" Then I think that some are counted more than twice. – leonbloy Jan 23 '15 at 18:29
  • For example, the all zeroes string is counted (in the first term) six times – leonbloy Jan 23 '15 at 18:35
  • @leonbloy. Yes; in the updated version I recognize that a string with 5+n zeros consecutively will counted n+1 times as a 5-string and n times as a 6-string, so the difference of those two is sufficient. – Joffan Jan 23 '15 at 22:22