# Thread: Recursive and Non-Recursive powersets?

1. Member
Join Date
Apr 2011
Posts
11
Rep Power
0

## Recursive and Non-Recursive powersets?

Hello all,

I need some help creating codes to make a powerset...

Here is the skeleton:

public static StringList powerRecursive (String s) {

}

public static StringList powerLooping (String s) {

}

Thanks!
Last edited by csisdifficult; 04-22-2011 at 02:51 PM.

2. If S is the set {x, y, z}, then the subsets of S are:

{} (also denoted , the empty set)
{x}
{y}
{z}
{x, y}
{x, z}
{y, z}
{x, y, z}

Is this what you are trying to do?

3. Member
Join Date
Apr 2011
Posts
11
Rep Power
0

## Yup!

Basically, but all in one string:

["", a, b, ab, ba, abab, baba]
Last edited by csisdifficult; 04-22-2011 at 02:51 PM.

4. Member
Join Date
Apr 2011
Posts
11
Rep Power
0

5. In one List, of course.

Something to start you off:

Java Code:
```//define a List because you don't know how many items you need to store in it
List<String> powerSet = new ArrayList<>();

//define set to make powerSet from
char[] aSet = new char[] {'a', 'b', 'c'};

//loop through each character
//define a String to store full set
String fullSet = "";
//add blank to List
for (int i=0; i<aSet.length; i++) {
//add each item in set
//compile the full set
fullSet += aSet[i];
}

So far this would get us everything except the 'ab', 'ac' and 'bc'.

ab, ac, bc... is like this: aa, ab, ac, ba, bb, bc, ca, cb, cc
but with same letter combos removed (aa, bb, cc)
and doubles removed (ab = ba, ac = ca, bc = cb)

6. Member
Join Date
Apr 2011
Posts
11
Rep Power
0
That sort of helps, I think I got it. Thanks!
Last edited by csisdifficult; 04-22-2011 at 02:52 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•