That's a clever way to do it! Though good look thinking that up on the spot.

What i did was, assuming the set has n elements:

for (i; from 0; to (2^n)-1)

{

generate binary represenation of i padded to n bits. (e.g if n=8, and i =4, representation would be 00100000). Call this representation "bitmap"

for (j; from 0; to bitmap.length)

{

if bitmap[j]==1: add set[j] to a tempset

}

add tempset to a global array of sets

}

return that global array of sets

Note that this has exponential complexity which i believe (but am not sure) is better than factorial complexity

How about something like this? Running time is O(n!).

(Java)

/**

* The power set of S is the set of all subsets of S, including the empty

* set and S itself. It is parallel to the idea of all combinations of

* characters in a string.

*/

public Set> getPowerSet(Set s){

Set> pset = new HashSet>();

Object[] a = s.toArray();

// Add the empty set

Set subset = new HashSet();

pset.add(new HashSet(subset));

int n = s.size();

this.getPset(a,subset,pset,n,0);

return pset;

}

private void getPset(Object[] a, Set subset, Set> pset, int originalSize, int currentSize){

for (int i = currentSize; i (subset));

if (i ();

}

}