The problem is to find the number of repeatable binary strings of length n.A binary string is repeatable if it can be obtained by any sub string of the binary string that repeats itself to form the original binary string.
Example
"1010" is a repeatable string as it can be obtained from "10" by repeating 2 number of times
"1001" is not a repeatable string as it cannot be obtained from any sub string of "1001" by repeating them any number of times
The solution I thought of is to generate all possible binary string of length n and check whether it is is a repeatable or not using KMP algorithm, but this solution is not feasible even for small n like n=40.
The second approach I thought is
Example for n = 6 we have divisor 1,2,3
for length 1 we have 2 sub string "1" and "0" that repeats itself 6 times so "111111" and "000000" are repeatable strings
for length 2 we have 4 sub strings "00" "01" "10" "11" so "000000" "010101" "101010" and "111111" are repeatable strings
similarly for length 3 we have 8 strings that are repeatable.
In the above example the string "111111" and "000000" was counted 3 times for each of the divisor.so clearly I am over counting.I need to subtract duplicates but I can't think of anyway to subtract duplicates from my actual count How can I do that?
Am I headed in the right direction or do I need to any other approach?
At each position of the string there can only be two possibilities, i.e., 0 or 1. Therefore, the total number of permutation of 0 and 1 in a string of length N is given by 2*2*2*… (N times), i.e., 2^N.
Answer and Explanation: A bit string of length 4 would have all the binary numbers between, 0000 and 1111 . There can be no other permutations or arrangements of the digits that can contain consecutive 1s. Hence there must be 10 bit-strings of length 4 which do not have consecutive 1s.
Bit string : a string of 0s and 1s. For example, “00101” and “11110” are bit strings of length 5. For length 8, there are two ways to select the first bit, two ways to select the second, … So in total, 2^8=256 possibilities for length 8.
When you use the second scheme remove the sub strings which made of repeatable binaries. For instance, 00 and 11 are made of the repeat of 0 and 1 respectively. So for length of 2 only consider the "01" and "10" for length of 3 only consider "001", "010", "011", "100", "101", "110" ... generally, for odd length of n remove 0 and (2^n)-1, for even length of n, remove 0, (2^(n/2)+1), (2^(n/2)+1)2, ...., (2^n)-1 and if n dividable by 3, (1+2^(n/2)+2^(n-2)), (1+2^(n/2)+2^(n-2)) 2, ... continue this for all divider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With