Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > search all subsets?

Reply
Thread Tools

search all subsets?

 
 
Patrick
Guest
Posts: n/a
 
      12-21-2007
Hi,
I want to write a programs that checks if a set of numbers in a list
obey a condition, the problem is that i have say "n" numbers and i
need to check all subsets of the n numbers for the condition.
How do i go about asking c++ to find the subsets and then check??

Thanks:
Patrick
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-21-2007
Patrick wrote:
> I want to write a programs that checks if a set of numbers in a list
> obey a condition, the problem is that i have say "n" numbers and i
> need to check all subsets of the n numbers for the condition.
> How do i go about asking c++ to find the subsets and then check??


AFAIK, C++ doesn't have "subset of M from N" kind of functionality.
You'd have to roll your own.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
fred.l.kleinschmidt@boeing.com
Guest
Posts: n/a
 
      12-21-2007
On Dec 21, 9:16*am, Patrick <natbro...@gmail.com> wrote:
> Hi,
> I want to write a programs that checks if a set of numbers in a list
> obey a condition, the problem is that i have say "n" numbers and i
> need to check all subsets of the n numbers for the condition.
> How do i go about asking c++ to find the subsets and then check??
>
> Thanks:
> Patrick


The algorithm you use will depend on what condition must be obeyed.
For example, if the condition is that the subset must not contain any
odd numbers, it is pretty easy. However, if the condition is that the
subset must contain as many of the original numbers as possible but no
three are allowed to sum up to 172, then it is a lot trickier.
--
Fred Kleinschmidt
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      12-21-2007
wrote:
> On Dec 21, 9:16 am, Patrick <natbro...@gmail.com> wrote:
>> Hi,
>> I want to write a programs that checks if a set of numbers in a list
>> obey a condition, the problem is that i have say "n" numbers and i
>> need to check all subsets of the n numbers for the condition.
>> How do i go about asking c++ to find the subsets and then check??
>>
>> Thanks:
>> Patrick

>
> The algorithm you use will depend on what condition must be obeyed.
> For example, if the condition is that the subset must not contain any
> odd numbers, it is pretty easy. However, if the condition is that the
> subset must contain as many of the original numbers as possible but no
> three are allowed to sum up to 172, then it is a lot trickier.


I prefer to check for membership in the set of all sets that do not
contain themselves


 
Reply With Quote
 
Kira Yamato
Guest
Posts: n/a
 
      12-22-2007
On 2007-12-21 12:16:08 -0500, Patrick <> said:

> Hi,
> I want to write a programs that checks if a set of numbers in a list
> obey a condition, the problem is that i have say "n" numbers and i
> need to check all subsets of the n numbers for the condition.
> How do i go about asking c++ to find the subsets and then check??


Usually, statements that say something about the set of *all* subsets
of a set can be restated as one that just say something about the
original set. So, you might want to try to restate the condition first.

If that doesn't work, then you can try to see if the condition is
stable under some set operations. By "stable under set operations," I
mean this:
(1) "If subsets A and B satisfy the condition, then so does A union B."
or
(2) "If subsets A and B satisfy the condition, then so does A intersect B."
or any other set operations. If so, then it is easy. Suppose it
satisfies (1), then you just need to check the condition for subsets of
cardinality 1 (there will be n of them). And if those checks out, then
you can use (1) to conclude that *all* subsets satisfy it. Similarly,
you can work out the equivalent tricks for (2) or any other set
operations.

However, if even that doesn't work, then I don't have any more
suggestion to give you other than just writing code to iterate through
all the subsets. As far as I know, standard C++ has no ready-to-roll
facility to do this. You just have to write the code. It's not really
that hard anyway. Just use an array of bits, use its bit pattern to
determine membership, then increment the array to iterate to the next
subset.

--

-kira

 
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
Search jobs at world's largest online job search engine. Findresources for all types of solomanjo@gmail.com Computer Support 0 03-13-2008 12:00 PM
Search jobs at world's largest online job search engine. Findresources for all types of solomanjo@gmail.com Digital Photography 0 03-13-2008 11:49 AM
| SEO , Search Engine Optimizer, SEARCH OPtiMIzAtIoN with SeaRch OPtiMizer optimizer.seo@gmail.com Digital Photography 0 04-22-2007 04:20 AM
Search All Records in Any State and Country Online Backgroundcheck Search PrincessDianne ASP .Net 0 08-24-2006 01:20 AM
search within a search within a search - looking for better way...my script times out Abby Lee ASP General 5 08-02-2004 04:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57