Painting houses

January 21st, 2005 ~ Posted in: Mathematics

Given a positive integer k, how many strings of length k can you construct that satisfy the following restrictions: each character in the string is a ‘b’ or a ‘w’, no ‘b’ can be followed by a ‘b’.

One interesting thing about this problem is that it shows in a straightforward manner that the special number you get is always less than or equal to 2^k. For that reason alone, it’s an interesting problem.

Since I could solve this one in the first go, here’s my solution:

For convenience, count places in the string from right to left, with the rightmost being position 1. Let C_w(p) and C_b(p) denote the number of strings that can be constructed beginning with a ‘w’ or a ‘b’, respectively, from the p-th position. What we’re trying to determine, the number of strings with length k, is therefore N(k) = C_w(k) + C_b(k). Convince your self that

C_w(p) = C_w(p-1) + C_b(p-1) and
C_b(p) = C_w(p-1),

also, it is clear that C(w)=1 and C(b)=1. Manipulating these, C_w(p) = C_w(p-1) + C_w(p-2), so C_w(p) = f_k, the k-th Fibonnaci number. Then N(k) = f_k + f_{k-1} = f_{k+1}. So the wanted number of strings is f_{k+1}. This shows that f_{k+1} < 2^k, because 2^k is the total number of strings consisting of ‘b’s and ‘w’s with length k.

You could probably show this inequality using the closed form expression for f_k also, but it’s neat that it falls out so clearly here.

This entry was posted on Friday, January 21st, 2005 at 3:00 pm and is filed under Mathematics. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply