# Calculate the total number of combinations over n elements, where the number of elements in each subset is in {0,..,n}?

If you had 4 elements, and you wanted to find all possible combinations of those 4, you take the factorial. But, what if you also wanted to consider combinations of 3, 2, 1 and 0 (where you're still using those 4 elements)? If you have n elements, and want to find all combinations of n, (n -1), (n -2) and so on, how would you go about it?

Also, sorry if I didn't word this question correctly.

If order doesn't matter, you can use ${n \choose 0} + {n \choose 1} + {n \choose 2} + \dots + {n \choose n} = 2^n$

The intuition here is that we're simply summing up all the possible combinations of different length-ed sets. We start with the combinations of length zero (there's only one - the empty set), and then add the combinations of length one (there's $n$ of them), etc. until we get to adding the combinations of length $n$ (there's only one).

Johanna's answer gives a good intuition of the $2^n$ value. Another way to think about it, is whenever we add a new element to the set, it must cause the number of possible subsets of that set to double in size. Think about it: All the previous possible subsets are still possible, but now we can create a copy of each of them that contains the new element - in doing so we double the number of possible subsets.

If order does matter you can use: ${n \choose 0}0! + {n \choose 1}1! + {n \choose 2}2! + \dots + {n \choose n}n!$

All we do here is multiply each element in the last equation by the number of different arrangements that are possible for each length. If, for example, we're considering a set of 7 elements, there are $7!$ different ways of rearranging that set. Note that this assumes that your set elements are unique (i.e. it's a proper set). If you have duplicate elements, don't use this formula (because, for example, it will count the ordered set AAB twice, given that we can switch the positions of the As).

Perhaps an easier way to think about the ordered case it we're just summing permutations of each possible length: $^n P_0 + ^n P_1 + ^n P_2 + \dots + ^n P_n$

• If I have elements [A, B, C] then I can make [A, B, C, AB, AC, BC, ABC]. I'm counting seven unique combinations, not 2^3=8 Commented Jun 26, 2020 at 14:22
• @DanielFreeman This will include the empty set, so [, A, B, C, AB, AC, ABC] Commented Feb 24, 2021 at 17:41

What you are looking for is every possible subset of the set of elements (in this case $4$ of them). To find that, you can either choose or not choose every element, so you have two choices for each element. Hence there are $2^n$ subsets of a set of size $n$.

EDIT: If order matters then we have more of them: $n + n(n-1) + n(n-2) + \dots + n!$ in particular. I'm not sure what the closed form of this (if any exists) is.

• I didn't even think of a power set... I feel dumb haha Can you go a bit into more detail and explain why the number is (2^n)? Commented Jan 24, 2015 at 3:53
• @JulianJefko There is a cool identity relating power sets with combinations: ${n \choose 1} + {n \choose 2} + \dots + {n \choose n} = 2^n$. Commented Jan 24, 2015 at 3:54
• But, if I had 3 elements, A B and C, the possible combinations are A,B,C, AB, AC, BC, BA, CA, CB, ABC, ACB, and so on. So, I have more than eight. Im sorry, I should've said order matters. Commented Jan 24, 2015 at 3:59
• Interesting! Thank you! Commented Jan 24, 2015 at 4:08
• @Johanna I think you've forgotten ${n \choose 0}$. So it should be ${n \choose 0} + {n \choose 1} + {n \choose 2} + \dots + {n \choose n} = 2^n$
– user270617
Commented Nov 7, 2016 at 4:20

You are looking for $\binom{0}{n}\cdot n! + \binom{1}{n}\cdot(n-1)! + \binom{2}{n}\cdot(n-2)! + \cdots + \binom{n}{n}\cdot 0!$.