List of Standard Counting Problems

List of Standard Counting Problems
Advanced Problem Solving
This list is stolen from Daniel Marcus’ Combinatorics—a Problem Oriented Approach (MAA,
1998). This is not a mathematical standard list, just a nice orderly way to keep track of basics.
1. Find the number of strings of length k using n different characters (no restrictions on
character use).
Answer: nk. Each of k slots has n different choices, so multiplication principle says to multiply n
with itself k times.
2. Find the number of strings of length k using n different character, no character used
more than once. (Permutations of n objects taken k at a time.)
n!
. We also called this the falling factorial,
(n − k)!
denoted n k . There are n choices for the first letter, n – 1 for the second, and so forth. Or,
arrange all n letters (n! ways) but disregard the unused n – k of them (so divide by (n – k)!).
Answer: n(n – 1)(n – 2)  (n – k + 1) =
3. Find the number of combinations (order doesn’t matter) of length k consisting of
different characters from an alphabet of n characters. (Combinations of n objects taken k
at a time.)
⎛ n ⎞
n!
= ⎜ ⎟ . Take the permutations from #2 and divide by k! because we don’t
k!(n − k)! ⎝ k ⎠
care about order in the first k elements.
Answer:
4. Find the number of bit strings that contain a 0’s and b 1’s but do not contain any two
consecutive 1’s.
⎛ a +1 ⎞
Answer: ⎜
. Take a row of a 0’s, and insert the 1’s in the a + 1 spaces between, before,
⎝ b ⎟⎠
and after them. In other words, take .0.0.0.0.0.0.0. and replace a choice of the dots with 1’s.
5. Find the number of combinations of length k from a set of n objects, allowing
repetitions, but using all elements at least once.
⎛ k −1 ⎞
Answer: ⎜
. Make a string of k blanks: _ _ _ _ _ _ _ _ and in the k – 1 spaces between
⎝ n −1 ⎟⎠
them place commas in n – 1 of those spaces. The first comma separates between A and B, the
second between B and C, and so forth. Because the commas are between the spaces, there is at
least one of each letter.
6. Find the number of combinations of length k form a set of n objects, allowing repititions,
with no other requirements.
⎛ n + k −1 ⎞
Answer: ⎜
. This is the “stars and bars” problem. Make a row of k stars, with n – 1
⎝ n −1 ⎟⎠
bars anywhere in, before, or after the row. Replace all stars before the first bar (if any!) with A,
between the first and second (if any) with B and so on. There are k + n – 1 total stars and bars, of
which n – 1 are bars. OR make a combination of k + n characters with at least one of each letter
as in problem 5, then delete the first occurrence of each letter.
7. Find the number of 0-dominated strings of a 0’s and b 1’s.
⎛ a+b ⎞ ⎛ a+b ⎞
Answer: ⎜
. (As long as b ≥ a.) How many such strings are not 0−
⎝ a ⎟⎠ ⎜⎝ a +1 ⎟⎠
⎛ a+b ⎞
dominated? Take a string with a + 1 0’s and b – 1 1’s. There are ⎜
of these. Find the
⎝ a +1 ⎟⎠
shortest initial fragment where 0’s outnumber 1’s (since there are a + 1 > a ≥ b > b – 1 0’s and
only b – 1 1’s, there must be such a fragment). Flip each bit of this string. There must be
exactly one more 0 than 1 in this fragment, so this produces a string with a 0’s and b 1’s, and this
string is not 0-dominated (because in this initial fragment there are more 1’s than 0’s). Because
any non-0-dominated string has an initial fragment with more 1’s than 0’s, if you find the
shortest such initial fragment and flip each bit, you get a string with a + 1 0’s and b – 1 1’s, so
this relationship between non-dominated strings with a 0’s and b 1’s and arbitrary strings with
one more 0 and one fewer 1 is a one-to-one correspondence. So we know how many nondominated strings there are, we simply subtract this from the total number of strings with a 0’s
⎛ a+b ⎞
and b 1’s, ⎜
.
⎝ a ⎟⎠
Side note: to find the total number of 0-dominated strings of total length n, we add the
numbers of such strings for all possible b. The smallest possible b is ⎡⎢n / 2⎤⎥ (ceiling, or least
integer greater than or equal to the number). So we get:
n ⎞⎞ ⎛⎛
n ⎞ ⎛
n
⎛⎛ n ⎞ ⎛
⎛⎛ n ⎞ ⎛ n⎞⎞ ⎛⎛ n⎞ ⎞ ⎛ n ⎞
⎞⎞
⎜⎜ n / 2 ⎟ − ⎜ n / 2 +1⎟⎟ + ⎜⎜ n / 2 +1⎟ − ⎜ n / 2 + 2⎟⎟ +⎜⎜⎝ n −1⎟⎠ − ⎜⎝ n⎟⎠⎟ + ⎜⎜⎝ n⎟⎠ − 0⎟ = ⎜ n / 2 ⎟ .
⎤⎥⎠ ⎝ ⎡⎢
⎤⎥ ⎠⎠ ⎝⎝ ⎡⎢
⎤⎥ ⎠ ⎝ ⎡⎢
⎤⎥ ⎠⎠
⎤⎥⎠
⎝
⎠ ⎝
⎠ ⎝ ⎡⎢
⎝⎝ ⎡⎢
8. Find the number of distributions of k distinct balls into n distinct boxes. Equivalently,
find the number of functions from a set of k objects to a set of n objects.
Answer: nk. This is really the same as problem 1. Number the balls from 1 to k, and label the
boxes with the letters of the alphabet. The box into which ball 1 goes comes first in the string,
the box into which ball 2 goes comes second, and so forth.
9. Find the number of distributions of k identical balls into n distinct boxes.
⎛ n + k −1 ⎞
Answer: ⎜
. This is the same as problem #6. Since the balls are identical, order no
⎝ n −1 ⎟⎠
longer matters, so we are taking combinations of k letters from an n letter alphabet, where there
are no restrictions on how many of each letter we may take.
10. Find the number of distributions of k identical balls into n distinct boxes, if no box is
allowed to be empty.
⎛ k −1 ⎞
Answer: ⎜
. This is the same as problem #5. Notice that the binomial coefficient is zero
⎝ n −1 ⎟⎠
if the top number is smaller than the bottom. Start by placing one ball into each box. That
leaves you with k – n balls to place as in problem #9, so replace k by k – n in that answer.
11. Find the number of distinct balls into distinct boxes, where box 1 must contain b1 balls,
box 2 must contain b2 balls, etc.
(b1 + b2 + + bn )! ⎛ b1 + b2 + + bn⎞
. This is the multinomial coefficient. It can be
=⎜
b1 !⋅b2 !⋅⋅bn !
⎝ b1, b2 ,…, bn ⎟⎠
found by multiplying the binomial coefficient for choosing b1 of the total balls to put into the
first box, then choosing b2 of the remaining balls to put into the second box, and so forth. Many
of the factorials in the binomial coefficients cancel, leaving the expression above.
Side note: multinomial coefficients are used to expand multinomials (like (x + y + z)n)
with any number of terms added together inside the parentheses just like binomials are used to
expand binomials.
Answer:
12. Find the number of rearrangements of the letters in a given word (including not
changing the order at all).
Answer: same multinomial coefficient as in 11, if there are b1 of the first letter, b2 of the second,
and so forth. Basically, take all possible rearrangements of all the letters, (b1 +  + bn)!, and
divide by each bi! because we can’t distinguish the identical letters being rearranged.
13. Find the number of distributions of k distinct balls into n boxes with no empty boxes.
14. Find the number of words of length k from n letters, if each letter must be used at least
once in each word.
Answer: These two are equivalent (the numbers on the balls tell the position of the letter on the
box within the word, as in comparing problems #8 and #1). The answer is to add up all
possibilities in problem #12 where each bi is at least one and the b’s add to k. The notation we
will use for this is T(k, n):
T(k, n) =
∑
b1,b2 ,…,bn ≥1
b1 +b2 ++bn =k
k
⎛
⎞
⎜⎝ b , b ,…, b ⎟⎠ . The T numbers can be found in a triangle somewhat like
1 2
n
Pascal’s triangle, except instead of merely adding the two numbers above you also multiply the
sum by the position within the row: T(k, n) = n(T(k – 1, n – 1) + T(k – 1, n)). The triangle looks
like this:
1
1
2
1
6
6
1
14
36
24
1
30
150
240
120
1
62
540
1560
1800
720
The explanation of this formula is to look at the first character of a string of k characters. Let’s
say it’s an A. If it is the only A in the string the rest of the characters form a length k – 1 string
with n – 1 characters each used at least once, of which there are T(k – 1, n – 1). If it is not the
only A, the rest of the characters form a length k – 1 string using all letters at least once, of which
there are T(k – 1, n). Adding these two gives all the possible strings of k letters using each at
least once that start with A. There are, of course, n different choices to start the string, so we
multiply by n to obtain the final answer.
15. Find the number of ways to arrange k distinct flags on n flagpoles.
(n + k −1)!
. We also called this the rising factorial n k .
(n −1)!
If there are a flags on a pole, there are a + 1 spaces to put the next flag on this pole. So every
time we place a flag on a pole we increase the total number of possible spaces to place the next
flag by one. Start with n empty poles, so that each has one space. Now add flags one at a time,
and we have n choices for the place to put the first flag, n + 1 choices for the second, and so on.
Answer: n(n + 1)(n + 2)(n + k – 1) =
16. Find the number of ways to arrange k identical flags on n flagpoles.
⎛ n + k −1 ⎞
Answer: ⎜
. This is the same as problem #9. Or, take problem #15 and divide by k!
⎝ n −1 ⎟⎠
because we can no longer tell the flags apart.
A partition is a distribution where you can’t tell groups of the same size apart. That is, it is a
distribution of k distinct balls into n identical boxes. Order within a box and order of boxes with
same numbers of elements doesn’t matter. For examples, there are 15 partitions of ABCDEF
into three groups of two:
AB CD EF
AC BD EF
AD BC EF
AE BC DF
AF BC DE
AB CE DF
AC BE DF
AD BE CF
AE BD CF
AF BD CE
AB CF DE
AC BF DE
AD BF CE
AE BF CD
AF BE CD
⎛ 6 ⎞
6!
Notice that ⎜
=
= 90 but that the six orders of the boxes don’t matter, so we should
⎟
⎝ 2,2,2 ⎠ 2!2!2!
divide by 6. This exemplifies the general answer to:
17. Find the number of partitions of k distinct objects into r1 groups of size 1, r2 groups of
size 2, …, rn groups of size n.
k
⎛
⎞
⎜ 1,1,...,1,2,2,...2, ,...,n,n,...,n ⎟

 


 
⎟
⎜⎝ 
⎠
r1
r2
rn
Answer:
. Note that we must have 1⋅r1 + 2⋅r2 +  + n⋅rn = k of
r1 !r2 !rn !
course. This is determined by figuring out the distributions of the k objects into the given
number of boxes of given sizes (which is given by the multinomial coefficient) and then dividing
by the rearrangement of each number of boxes of the same size that can’t be distinguished from
each other.
18. Find the number of partitions of k objects into a specified number n of nonempty
subsets, where we don’t specify the sizes of the subsets.
T (k,n) ⎧ k ⎫
= ⎨ ⎬ . Recall the T numbers tell the number of ways of placing k distinct balls
n!
⎩n ⎭
into n distinct boxes, with no box empty. Since we can no longer tell the boxes apart, we divide
by n!. These are also called Stirling numbers of the second kind or Stirling subset numbers and
are also notated S(k, n). Here is a table:
1
1
1
1
3
1
1
7
6
1
1
15
25
10
1
1
31
90
65
15
1
Answer:
The rule that generates this table is: S(k, n) = S(k – 1, n – 1) + nS(k – 1, n). This can be proven
using the T numbers, but has a direct proof as follows. If object k is in a class all by itself, then
the other k – 1 objects can be arranged into n – 1 classes in S(k – 1, n – 1) ways. But if object k
goes into an already established class, there are n choices for this class in each of the S(k – 1, n)
partitions of the other k – 1 objects into n classes.
Finally, let’s discuss indistinct balls in indistinct boxes.
19. How many ways are there to place k identical balls into n identical boxes with no box
empty?
20. How many ways are there to write k as the sum of n nonzero numbers?
These questions are clearly identical. There is no nice formula for the answer, but let’s see if we
can find a way to figure them out. Define this number to be P(k, n), partitions of k into n parts.
We start by noticing the relationship between partitions of k and of k – 1. If you take away one
ball, under what conditions do you keep the same number of boxes? Well, only if the box from
which you take the ball has another ball in it. That is, let’s say we take away one ball from (one
of) the box(es) with the fewest balls. We could be left with k – 1 balls in n – 1 boxes if the ball
we took was the only ball in that box, or else all boxes had at least two balls to start with. That
means that P(k, n) = P(k – 1, n – 1) + P2(k, n), where P2 means partitions where each box has at
least two balls in it.
But it is fairly easy to see that P2(k, n) = P(k – n, n), simply by taking one ball out of each
of the n boxes. So now we have a recursion: P(k, n) = P(k – 1, n – 1) + P(k – n, n). Of course,
P(a, b) must be zero if b > a since we have to have at least one ball in each box. That allows us
to start the following table:
1
1
1
1
1
1
1
2
1
1
1
2
2
1
1
1
3
3
2
1
1
Some things to note: P(n, 1) = P(n, n) = P(n, n – 1) = 1 while P(n, 2) = ⎢⎣ n / 2 ⎥⎦ .