console.blog()

a "technical" "blog" by Eric Zheng

Fibonacci Strings
Summary: just a distraction from impending midterms

So as I was working on a problem set for 15-252 (also known as the bane of my life, devourer of my week, et cetera), I stumbled upon a very cute special case of a more general statement that I was trying to (and failing to1) prove. The statement and its proof are fairly short/clean, so I figured I could type it up both as a fun puzzle and as a way to avoid studying for my 21-268 midterm. (Update: the midterm still didn’t go as well as I’d have liked. Perhaps procrastination is not a good idea after all.)

Anyway, here’s the question for you:

How many binary strings of length are there without any pair of consecutive zeros?

If you’d like, you can stop reading and try to come up with the answer on your own; it’s not a very long proof. Actually, I think it’s very similar to the domino tiling problem, if you’ve ever seen that one before. (Oops, I think I gave away the answer in the title.)

intuition

Anyway, I’ll first present the intuition behind the main claim. Granted, for a statement this simple I don’t think an “intuitive” exposition really adds anything, but it’s helpful for more general cases and tends to be a somewhat overlooked practice in mathematics.

When I approached this problem, I actually thought of it graphically in terms of a tree. Consider a binary tree of depth , where the label the left and right edges with and respectively:

representation of the problem as a binary tree

Then we can let each of the leaf nodes (at the bottom) represent one binary string of length , based on the path used to get there from the root node (at the top). For instance, the leftmost leaf node would represent the binary string , since we would need to take the path consisting of all ’s to get there. The problem now becomes one of counting the valid leaves in the tree.

Now let’s consider the left subtree. If we go left twice, then our string will start with , which is no good. In fact, if at any point in a given path we travel left twice consecutively, the resulting subtree will be no good. Visually, we cross out all such subtrees:

cross bad subtrees

Now what’s left? Well, we could try to enumerate the nodes, but there’s actually a very beautiful recursive pattern than we could use instead. Observe that the left-left tree is absolutely no good; any leaf in that tree will not be valid. In the left-right subtree, we get a very similar picture to the overall tree, except that there are now levels instead of levels. Similarly, in the right subtree, we get another similar picture, this time of depth . Visually, this is to say:

recursive structure

So how many valid leaves are there in the overall tree of depth ? Well, it’s just the sum of the number of valid leaves in two “similar” trees of depths and . A recursive structure? Sounds like a proof by induction to me!

more formally…

Claim: Denote to be the number of -bit binary strings without any pair of consecutive zeros. Then is precisely the -th Fibonacci number2.

Proof: By strong induction on .

  • Base case: If (i.e. the string has zero or one bits), then clearly we cannot have a pair of consecutive zeros. In this case, is just the total number of -bit binary strings, so . We indeed have that and , which are the first and second Fibonacci numbers respectively.
  • Inductive step: Suppose , and assume the claim for all . Now we can parition all binary strings of length into three groups based on their prefix:
    • If the string starts with , then the remaining bits can be any string that does not itself contain a consecutive pair of zeros. By the inductive hypothesis, there are such strings.
    • If the string starts with , then the remaining bits can be any string that does not itself contain a consecutive pair of zeros. By the inductive hypothesis, there are such strings.
    • If the string starts with , then no matter what the remaining bits are, the string will not have the desired property; we’ve already found a pair of consecutive zeros in it.

    Hence in total we have . This is the -th Fibonacci number, as claimed. ∎

In fact, it easy to see how the claim generalizes to binary strings of length without any consecutive sequence of zeros for any natural and .


1 Fun fact: . This is not very difficult to see, but it took me an embarrassingly long time to realize this. This is not what I was trying to prove, but it greatly simplified the bound I was trying to prove. I still didn’t manage to prove the full bound.

2 Here we take the conventional definition of the Fibonacci numbers as , where we start indexing at zero. Hence we consider the zeroth Fibonacci number to be and the fourth to be .