4

I have a set of N numbers. How many possible M-combinations - with M > N - of the N numbers are there which contain every number at least once?


Example:

Numbers {1,2} and hence N = 2 and M be 3.

Possible 3-combinations:

1,1,1 (no)
1,1,2 (yes)
1,2,1 (yes)
1,2,2 (yes)
2,1,1 (yes)
2,1,2 (yes)
2,2,1 (yes)
2,2,2 (no)

Answer would be 6.

joriki
  • 238,052
Raffael
  • 145

1 Answers1

8

I'll use the more standard terminology of using lowercase letters, so $n$ will denote your $N$, the number of numbers (which I'll call letters from here on to avoid confusion) available to use in your string, and $m$ will denote your $M$, the length of your string. You can do an inclusion-exclusion sieve. There are $n^m$ total strings of length $m$ from an alphabet with $n$ letters. That's an overcount, so subtract, for each of the $n$ letters, the amount $(n-1)^m$, which equals the total number of strings of length $m$ not using the chosen letter, so there are now $n^m - n (n-1)^m$ such strings. But this is an undercount, because we subtracted strings that are missing at least two letters too many times. So we need to add in, for each ${n \choose 2}$ pairs of letters, the amount $(n-2)^m$. But now this is an overcount again, and so it goes. Thus, we get that the number of strings of length $m$ using each of the $n$ letters at least once is $$ n^m - {n \choose 1} (n-1)^m + {n \choose 2} (n-2)^m - {n \choose 3} (n-3)^m + \cdots = \sum_{k=0}^{n} (-1)^k {n \choose k} (n-k)^m. $$

Your number is equal to $n!$ times $S(m,n)$, where $S(m,n)$ stands for a Stirling number of the second kind.

joriki
  • 238,052
Michael Joyce
  • 14,126
  • Oh nice! Does this question/problem have a name? It seems to be a fairly practically relevant problem so I would assume it can be referred to somehow. I would also like to google a bit more about it. – Raffael Feb 28 '14 at 07:55
  • The intuitive explanation you give is great! But I wonder how one might proove this formula. Do you know something about the availability of a formal proof? – Raffael Feb 28 '14 at 07:59
  • Click the link to the wikipedia article on Stirling numbers of the second kind. A google search or most intro to combinatorics textbooks will have more information. Your problem can be interpreted as counting the number of surjective functions from an $m$-element set to an $n$-element set. You just interpret your list of numbers $a_1, a_2, \dots, a_m$ as $f(1), f(2), \dots, f(m)$. The fact that each number in this list must be between $1$ and $n$ says that you have a function to a set with $n$ elements, and the fact that each number must appear on the list says the function is surjective. – Michael Joyce Feb 28 '14 at 12:55