Subset

This is a discussion on Subset within the C++ Programming forums, part of the General Programming Boards category; i want to determine al possible subsets from a given set( it may be integers or chars) using recursion only..... ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    5

    Subset

    i want to determine al possible subsets from a given set( it may be integers or chars) using recursion only.....
    can some1 help me in making an algo for it???

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Homework? You probably won't get much help here unless you show that you've made a step towards trying to solve it yourself. Post some code. Tell us where your problems are. We'll help.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    lolzz yups its a homework....i just want to get an idea how to start it....rest i can do it myself...

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    Hint: suppose your set is A = {a1, a2, ..., aN}. Suppose P(A) is the set of all subsets of A.

    Then P(A) = subsets of A that don't have a1 + subsets of A that do have a1, or:

    P(A) = P(A\{a1}) + {B+{a1} : B in P(A\{a1})},

    where A\{a1} is the set you get when you remove the element a1 from A and + is the union of two sets.

    This suggests an obvious recursive algorithm.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    thanx man!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. subset algorithm
    By calc in forum C Programming
    Replies: 5
    Last Post: 06-24-2009, 01:06 PM
  2. what code to enter for subset function?
    By ismee in forum C Programming
    Replies: 8
    Last Post: 12-04-2008, 11:19 AM
  3. Find all possible subset of a given set
    By Downnin in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 02:03 PM
  4. Finding a 'Proper Subset'
    By SlayerBlade in forum C Programming
    Replies: 1
    Last Post: 09-28-2005, 06:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21