title: Obtaining a powerset of a set in Java
body: <p>The powerset of <code>{1, 2, 3}</code> is:</p>
  
  <p><code>{{}, {2}, {3}, {2, 3}, {1, 2}, {1, 3}, {1, 2, 3}, {1}}</code></p>
  
  <p>Let's say I have a <code>Set</code> in Java:</p>
  
  <pre><code>Set&lt;Integer&gt; mySet = new HashSet&lt;Integer&gt;();
  mySet.add(1);
  mySet.add(2);
  mySet.add(3);
  Set&lt;Set&lt;Integer&gt;&gt; powerSet = getPowerset(mySet);
  </code></pre>
  
  <p>How do I write the function getPowerset, with the best possible order of complexity?
  (I think it might be O(2^n).)</p>