TITLE: All unique combinations of n numbers
QUESTION [12 upvotes]: How is the algorithm or process called which calculates all unique combinations of n numbers? By unique I mean that this 1234 is the same as this 1243.
Example:
Take this 4 numbers and list all unique combinations:
1
2
3
4

Output:
1
2
3
4
12
13
14
23
24
34
123
124
134
234
1234

REPLY [14 votes]: There are $2^n-1$ non-empty subsets of the set $\{1,...,n\}$. Given a number $k=1,...,2^n-1$, we can write the $k$ as an $n$-digit binary number, and then put $i$ in the set $A_k$ if the $i$th binary digit of $k$ is $1$.
For example, $n=3$ yields:
$$\begin{array}{cc}\text k & \text {binary} & \text{set}\\
1 & 001 & \{3\}\\
2 & 010 & \{2\}\\
3 & 011 & \{2,3\}\\
4 & 100 & \{1\}\\
5 & 101 & \{1,3\}\\
6 & 110 & \{1,2\}\\
7 & 111 & \{1,2,3\}
\end{array}$$