Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How many $N$ digits binary numbers can be formed where $0$ is not repeated. Note - first digit can be $0$.

I am more interested on the thought process to solve such problems, and not just the answer.
If anyone can cite some resources for learning how to solve such problems would be great.

share|cite|improve this question
I'm in urgent need of a simple reference to this proof, in order to quote it in my scientific work. I want to includ this proof to support my other original work, and have to make a clear distinction of what's mine and what's not mine. Is there any common, standard, textbook that does this, that I can quote? -Robert – user59856 Jan 27 '13 at 16:34
An interesting sidenote : for n = 2,3,4,5 this relation holds : n + 2^(n-2). I was asked this question in an interview and made the mistake of starting with above relation and trying to prove it by induction :-). – dharm0us Mar 4 at 20:01
up vote 5 down vote accepted

First consider $B_{a}(n)$ as the number of "binary number" without 0 repeated of length $n$, which starts with $a$, with $a \in \left\{0, 1\right\}$. Then: $$B(n) = B_{0}(n) + B_{1}(n)$$ is the number of "binary number" without 0 repeated of length $n$.

We can know work on the $B_{a}(n+1)$. These number can build by adding $0$s or $1$s in front of a number of length $n$. In particular we have that: $$B_{0}(n+1) = B_{1}(n) \\ B_{1}(n+1) = B_{0}(n) + B_{1}(n) = B(n)$$

Summing up, we have that: $$B(n+1) = B(n) + B_{1}(n)$$

But it also clear from the previous relation that $B_1(n) = B(n-1)$ (since $B_{1}(n+1) = B(n)$ is true for $n$, then it is true even for $n-1$), so we finally have the recurrence relation: $$B(n+1) = B(n) + B(n-1)$$

At this point you have to determinate the number $B(1)$ and $B(2)$ and then apply the recurrence relation we have derived before.

We have $B(1) = 2$, since we have the sequences $[0]$ and $[1]$. Also, $B(2) = 3$, since we have the sequences $[0,1]$, $[1,0]$ and $[1,1]$.

So we can evaluate $B(3) = B(2) + B(1) = 5$ and so on.

Note: the recurrence relation is the same of the Fibonacci sequence.

share|cite|improve this answer
Thanks for the answer. – user1065734 Dec 18 '12 at 9:46
it would be great if you could provide any reference on solving such problems – user1065734 Dec 18 '12 at 9:46
well, actually I followed a lecture about those kind of problem and I don't know where to send you for further reading. However, the general trick is to think "how to build an object with parameter $\theta+1$ knowing that I already built the object with parameter $\theta$"... The wrong way (but not always wrong!) is to pretend to build the object by exploiting its internal structure for a fixed parameter $\theta$. By the way, in our case, the parameter $\theta$ is simply $n$. – the_candyman Dec 18 '12 at 9:51

One way to solve problems like this is with recurrence relations. If we let $a_n$ denote the number of binary words of length $n$ without adjacent $0$s, then we can derive a relationship between $a_n$ and the values $a_{n-1}$ and $a_{n-2}$.

In fact, we see that either the first digit is a $1$ or the first two digits are $01$, without any further constraints on the sequence. Thus $$ a_n = a_{n-1} + a_{n-2} $$ because these two cases are the only possibilities. Then, if you supply the "initial conditions" for $a_1$ and $a_2$, this gives a formula for $a_n$ by techniques given in the link above.

To learn more about this kind of technique, I would recommend the book by Graham, Knuth, and Patashnik "Concrete Mathematics: A Foundation for Computer Science". Many books and courses on discrete mathematics or enumerative combinatorics can also help.

share|cite|improve this answer
i got to the part that they can be formed by combining 1 and 01 only. could'nt follow up – user1065734 Dec 18 '12 at 9:25
Do you understand why $a_n = a_{n-1} + a_{n-2}$? – Pot Dec 18 '12 at 9:27
i meant that when i was solving the problem i could get to the part that they can be formed by 1 and 01 but could nt follow up. i understand your solution. – user1065734 Dec 18 '12 at 9:29
I see, glad to hear it! Recurrence relations are a very powerful technique, so it is well worth the time to study. – Pot Dec 18 '12 at 9:30
@user1065734: Note that if you work out the first few values by hand, you get $1,2,3,5,8,13$, which is immediately recognizable as the Fibonacci sequence. That would point you right away at the recurrence, and it’s easy then to verify that it does apply to this problem as well. – Brian M. Scott Dec 18 '12 at 9:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.