Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Recursive combinations algorithm

Reply
Thread Tools

Re: Recursive combinations algorithm

 
 
alexey.pyatovskiy@gmail.com
Guest
Posts: n/a
 
      02-15-2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on algorithm to calculate combinations Alexander Antonakakis Ruby 8 02-25-2010 06:19 PM
C++ algorithm for combinations of vector elements cayblood C++ 8 11-02-2005 04:24 AM
Algorithm for combinations... deancoo C++ 2 02-25-2005 12:53 AM
Algorithm to generate different combinations based on N numbers Peter R C++ 2 05-11-2004 03:26 PM
Combinations/permutations algorithm in C++ jose luis fernandez diaz C++ 6 04-13-2004 06:08 PM



Advertisments