Re: Recursive combinations algorithm

Discussion in 'C++' started by alexey.pyatovskiy@gmail.com, Feb 15, 2005.

  1. Guest

    Could you please explain what is the NullSet - are you emptying the
    set? I am lost..

    > You still have too many loops, a good sign that you haven't found an
    > "elegant" recursive solution.
    > Consider: You can divide the subsets of {a, b, c, d} into two groups:
    > subsets containing a and subsets not containing a.
    > The second case gives you an obvious recursion on {b, c, d}. What

    about
    > the first case? It simply the subsets of {b, c, d} with a added to

    each
    > one!
    >
    > Comb( Set CurrentSet, Set ElementsToAdd = NullSet )


    //here - what is NullSet?


    > {
    > if( CurrentSet.IsEmpty() )
    > {
    > ElementsToAdd.PrintSet();
    > }
    > else
    > {
    > Element x = CurrentSet.GetFirstElement();
    > Comb( CurrentSet - x, ElementsToAdd + x );
    > Comb( CurrentSet - x, ElementsToAdd );
    > }
    > }
    >
    > This assumes the existence of a Set class (not quite the same as the
    > standard C++ set template) with the appropriate member functions. In
    > particular, the + and - operators should return a copy of the left

    hand
    > operand with the right hand operand inserted and deleted

    respectively.
    >
    > Seth Jones
     
    , Feb 15, 2005
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jose luis fernandez diaz

    Combinations/permutations algorithm in C++

    jose luis fernandez diaz, Apr 13, 2004, in forum: C++
    Replies:
    6
    Views:
    14,443
    Leor Zolman
    Apr 13, 2004
  2. Peter R
    Replies:
    2
    Views:
    7,643
    Alex Vinokur
    May 11, 2004
  3. deancoo
    Replies:
    2
    Views:
    520
    deancoo
    Feb 25, 2005
  4. cayblood
    Replies:
    8
    Views:
    793
    Victor Bazarov
    Nov 2, 2005
  5. n00m
    Replies:
    12
    Views:
    1,313
  6. Alexander Antonakakis

    Help on algorithm to calculate combinations

    Alexander Antonakakis, Feb 25, 2010, in forum: Ruby
    Replies:
    8
    Views:
    294
    Josh Cheek
    Feb 25, 2010
  7. John O'Hagan
    Replies:
    0
    Views:
    201
    John O'Hagan
    Nov 21, 2013
  8. John O'Hagan
    Replies:
    2
    Views:
    185
    John O'Hagan
    Nov 23, 2013
Loading...