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. Advertising

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. John O'Hagan
    Replies:
    0
    Views:
    103
    John O'Hagan
    Nov 21, 2013
  2. Oscar Benjamin
    Replies:
    0
    Views:
    80
    Oscar Benjamin
    Nov 21, 2013
  3. John O'Hagan
    Replies:
    2
    Views:
    81
    John O'Hagan
    Nov 23, 2013
  4. Dan Stromberg
    Replies:
    0
    Views:
    86
    Dan Stromberg
    Nov 21, 2013
  5. MRAB
    Replies:
    0
    Views:
    102
Loading...

Share This Page