N-element combinations from K sets of different size

combinationscombinatorics

Sorry for the noob question, I can't find the answer anywhere else.

I am looking for a formula for the number of combinations of size N, from K sets, where each set has different number of elements.

Example:

  • I want to know the number of pairs -> N=2.
  • I have 3 sets -> K=3.
  • The size (cardinality) of these stets are -> K1=2, K2=3, K3=4.

My sets are:

  • K1 = (a, b)
  • K2 = (A, B, C)
  • K3 = (1, 2, 3, 4)

I am looking for the number of all unique pairs (no repetition) like these:

a-A, a-B, a-C, a-1, a-2, a-3, a-4,

b-A, b-B, b-C, b-1, b-2, b-3, b-4,

A-1, A-2, A-3, A-4,

B-1, B-2, B-3, B-4,

C-1, C-2, C-3, C-4

= total 26.

What is the formula for given size of combinations N, number of set K and their cardinalities (number of elements) Kx?

Best Answer

There is not a nice formula per se. Suppose that the sizes of the sets are $x_1,x_2,\dots,x_k$. In your example, $x_1=2,x_2=3,x_3=4$. The number of ways to select $n$ items, such that each selected item comes from a different set, can be written as $$ \sum_{1\le i_1<i_2<\dots<i_n\le k}x_{i_1}\cdot x_{i_2} \cdots x_{i_n} \tag1 $$ The summation ranges over all selections of $n$ distinct numbers $\{i_1,\dots,i_k\}$ between $1$ and $k$, so there are $\binom{n}k$ summation terms, each a product of the sizes of $n$ distinct sets. In your example, this becomes $$ x_1\cdot x_2+x_1\cdot x_3+x_2\cdot x_3=2\cdot 3+2\cdot 4+3\cdot 4=26 $$ The expression in $(1)$ comes up so often that it is given a special name. It is known as the elementary symmetric polynomial in variables $x_1,\dots,x_k$. If we let $e_n(x_1,\dots,x_k)$ denote the expression in $(1)$, then you can compute $(1)$ recursively as follows: $$ e_n(x_1,\dots,x_k)=x_k\cdot e_{n-1}(x_1,\dots,x_{k-1})+e_n(x_1,\dots,x_{k-1}) $$ This leads to a dynamic programming algorithm to calculate $(1)$ using $O(nk)$ arithmetic operations.

Related Question