Number of permutations in a list, including permutations of subsets of that list?

2.3k Views Asked by At

[1, 2, 3] has 6 permutations, i.e. 3!

[1, 2] has 2 permutations, i.e. 2!.

But, how do I compute the number of possible permutations in a list, given that I can arbitrarily remove any number of elements?

For example, [1, 2] would have [1], [2], [2,1], [1,2], []. So 5.

1

There are 1 best solutions below

3
On

The following analysis assumes the list contains no duplicate elements. Given a set of size $n$, each subset has size between $0$ and $n$. Given a size $0 \leq k \leq n$, there are precisely $\binom{n}{k}$ subsets of size $k$. Each subset of size $k$ has $k!$ permutations, so the total number of possible permutations of subsets is $$\sum_{k = 0}^n \binom{n}{k}k! = \sum_{k = 0}^n \frac{n!}{(n - k)!}.$$

Edit: If the list can contain duplicates, the analysis is not as clean. Suppose it has $n$ total elements, with $m$ distinct elements (where $1 \leq m \leq n$). Then, we can treat it as a multiset $S$, and let the set of $m$ distinct elements be $T$. The multiset can be represented as a function $\alpha : T \to \mathbb{Z}_+$, where for an element $t \in T$, $\alpha(t)$ states how many times $t$ appears in $S$. For example, if $S = \{a,a,b,c,b,b\}$, then $\alpha(c) = 1$, $\alpha(a) = 2$, and $\alpha(b) = 3$.

The number of permutations of a multisubset of $S$ can be computed using the formula for permutations with repetition. In our notation, if $U$ is a multisubset of $S$ represented by $\beta: T \to \mathbb{Z_+}$ where $\beta(t) \leq \alpha(t)$ for all $t \in T$, then the number of permutations of $U$ is $$\frac{|U|!}{\prod_{u \in U}\beta(u)!}.$$ The total number of permutations is then the summation of this quantity over all possible multisubsets $U'$ of $S$. Note that there are $\prod_{t \in T} (1 + \alpha(t))$ distinct multisubsets in total.