473,395 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

search all subsets?

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
Dec 21 '07 #1
4 3592
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
Dec 21 '07 #2
On Dec 21, 9:16*am, Patrick <natbro...@gmail.comwrote:
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
Dec 21 '07 #3
fr*****************@boeing.com wrote:
On Dec 21, 9:16 am, Patrick <natbro...@gmail.comwrote:
>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 :-)
Dec 21 '07 #4
On 2007-12-21 12:16:08 -0500, Patrick <na*******@gmail.comsaid:
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

Dec 22 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon | last post by:
Hi, I'm hoping you could show me examples of how a functional/declarative language could be used to consicely describe resticted subsets of elements. I'm looking for a 'specification' style...
4
by: Brett Calcott | last post by:
I've found some python solutions to find the set of subsets for a given set, but how do you find the set of the set of subsets whose union is the given set and whose intersections is the empty set....
9
by: ETL | last post by:
Hi, I have an xml document that feeds a treeview menu on my web site. The structure of the xml file is as follows. <XML type="text/xml"> <root> <a0 name="One"> <a0_0 html="Report 1" id="1" />...
6
by: Talin | last post by:
I've been using generators to implement backtracking search for a while now. Unfortunately, my code is large and complex enough (doing unification on math expressions) that its hard to post a...
7
by: Gaijinco | last post by:
I been thinking about this topic for a long time. The best I have done is the following code: #include <iostream> using namespace std; #include <cmath> int main(){ const int SIZE=3;
25
by: Jessica Weiner | last post by:
I have an array of n integers and I want a function that returns a list of arrays of all possible subsets. Can someone provide me with the code? Thanks. Jess
4
by: LurfysMa | last post by:
I could use some help with a table design problem. I have an electronic flashcard program. Actually, several of them. They each rely on a utility program to keep track of the usage statistics....
4
by: foolproofplan | last post by:
I am currently working on coding something in c++ which allows me to find locations (line/column) of certain elements and attributes within an xml file. For this task, I am trying to create a SAX...
1
by: Rajesh V | last post by:
Hi, The aim of this C++ code is to print all the k-element subsets of a set of size n. But somewhere it goes wrong - it doesn't print the answer properly. I tried a lot to find the mistake, but...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.