Given a finite string of symbols and , we write for the number 's in minus the number of 's. (For example, .) We call a string balanced if every sub-string of (consecutive symbols) has the property . (Thus is not balanced, since it contains the sub-string whose -value is .) Find, with proof, the number of balanced strings of length .
, 2007
Solution
The balanced strings consists of 's and 's arranged alternately, or with as many as two consecutive letters of the same kind. Such occurrences of double letters must happen alternately with an even number (possibly zero) of single letters between any two double occurrence. If is the number of balanced strings of length , we show that
For , we have the strings and , so that . For , the balanced strings are , , , so that . Similarly, we have for the balanced strings , , , , , , giving . However, for , we see that the strings are , , , , , , , , , and hence .
Let respectively denote the number of balanced strings of length that end with ; that end with and whose last occurrence of a double letter was ; and that end with , but whose last occurrence of a double letter was . Note that and can be interchanged
in any balanced string. Hence also denote the number of balanced strings of length that end with ; that end with and whose last occurrence of a double letter was ; and that end with , but whose last occurrence of a double letter was . This shows that (we count purely alternating strings and twice; once among and once among ). Thus . We can form the strings of length from such string of length in exactly the following ways;
(i) if already ending with , we may add either or , but nothing else;
(ii) if ending with , with last double occurrence , we can add or , but nothing else;
(iii) if ending with , with last double occurrence , we can add or , but nothing else.
This gives strings. Similarly, by interchanging and , we get more strings. Thus
Using the initial conditions, we get