Results 1 to 6 of 6
  1. #1
    csisdifficult is offline Member
    Join Date
    Apr 2011
    Posts
    11
    Rep Power
    0

    Default 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. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    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. #3
    csisdifficult is offline Member
    Join Date
    Apr 2011
    Posts
    11
    Rep Power
    0

    Default 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. #4
    csisdifficult is offline Member
    Join Date
    Apr 2011
    Posts
    11
    Rep Power
    0

    Default

    Please? Someone help?

  5. #5
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    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
        powerSet.add(fullSet);
    for (int i=0; i<aSet.length; i++) {
        //add each item in set
        powerSet.add(aSet[i]);
        //compile the full set
        fullSet += aSet[i];
    }
        //add full set
        powerSet.add(fullSet);

    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. #6
    csisdifficult is offline Member
    Join Date
    Apr 2011
    Posts
    11
    Rep Power
    0

    Default

    That sort of helps, I think I got it. Thanks!
    Last edited by csisdifficult; 04-22-2011 at 02:52 PM.

Similar Threads

  1. very frustrating.. recursive
    By Yakg in forum New To Java
    Replies: 5
    Last Post: 01-06-2011, 10:25 PM
  2. recursive function
    By jayden in forum New To Java
    Replies: 11
    Last Post: 09-02-2010, 03:00 PM
  3. recursive method
    By michail in forum New To Java
    Replies: 0
    Last Post: 01-31-2010, 01:50 PM
  4. basic help with Recursive
    By syntrax in forum New To Java
    Replies: 3
    Last Post: 12-15-2009, 06:19 AM
  5. Help with recursive implementation
    By toby in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 05:57 AM

Tags for this Thread

Posting Permissions

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