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

A) How many n-digit binary $(0,1)$ sequences contain exactly k "1"s?

B) How many n-digit ternary $(0,1,2)$ sequences contain exactly k "1"s?

I am familiar with the equations $\frac{n(n-1)}{2}$ and $\frac{n!}{k!(n-k)!}$ but I am not sure how to apply them in these questions.

share|cite|improve this question
up vote 4 down vote accepted

For part A, you may think of forming an $n$-digit binary sequence as filling in $n$ slots. Each slot either gets a "0" or a "1". The number of $n$-digit binary sequences with exactly $k$ ones is the number of ways to choose $k$ slots from the $n$ slots. The slots you choose get the "1"s, the others get "0"s. So, the number of $n$-digit binary sequences with exactly $k$ ones is $n\choose k$.

Part B is a bit trickier. You can choose the $k$ slots in which to insert the "1"s as we did above. The remaining $(n-k)$ slots do not get ones; but, each of these non-one slots can be filled with either a zero or a two. Consequently, using the multiplication principle, the number of $n$-digit ternary sequences with exactly $k$ ones is $$\eqalign{ &\textstyle\Bigl({\text{num. of ways to choose}\atop k\text{ slots for the ones}}\Bigr) \cdot\underbrace{\Bigl({\text{num. of ways to fill}\atop \text{leftmost empty slot}}\Bigr) \cdot\Bigl({\text{num. of ways to fill}\atop \text{next leftmost empty slot}}\Bigr) \cdots\Bigl({\text{num. of ways to fill}\atop \text{rightmost empty slot}}\Bigr)}_{(n-k)\text{-terms}}\cr } $$ Computing the above, we obtain $ {n\choose k}\cdot2^{n-k} $.

Of course, in the above, we assume $k\le n$...

share|cite|improve this answer

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.