The powerset of {1, 2, 3} is:
{1, 2, 3}
{{}, {2}, {3}, {2, 3}, {1, 2}, {1, 3}, {1, 2, 3}, {1}}
Let\'s say I have a Set in Java:<
Set
Here is a tutorial describing exactly what you want, including the code. You're correct in that the complexity is O(2^n).