473,387 Members | 1,379 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,387 software developers and data experts.

finding subset

1
Hi....
I have an array[4]={1,2,3,4}. I want to make a recursive program that will produce subsets from the array;
1
2
3
4
14
24
34
124
134
234
1234
is anybody could help me? thanks....
Mar 28 '07 #1
4 2556
JosAH
11,448 Expert 8TB
Those subsets are all possible combinations C(n, k) for a set of n elements.
There are 2^n of those sets and you can easily find them if you count in
binary:
Expand|Select|Wrap|Line Numbers
  1. 1 2 3 4
  2. --------
  3. 0 0 0 0 = <empty set>
  4. 0 0 0 1 = { 4 }
  5. 0 0 1 0 = { 3 }
  6. 0 0 1 1 = { 3 4 }
  7. 0 1 0 0 = { 2 }
  8. . . . .
  9. 1 1 1 0 = { 1 2 3 }
  10. 1 1 1 1 = { 1 2 3 4 }
  11.  
kind regards,

Jos
Mar 28 '07 #2
r035198x
13,262 8TB
Those subsets are all possible combinations C(n, k) for a set of n elements.
There are 2^n of those sets and you can easily find them if you count in
binary:
Expand|Select|Wrap|Line Numbers
  1. 1 2 3 4
  2. --------
  3. 0 0 0 0 = <empty set>
  4. 0 0 0 1 = { 4 }
  5. 0 0 1 0 = { 3 }
  6. 0 0 1 1 = { 3 4 }
  7. 0 1 0 0 = { 2 }
  8. . . . .
  9. 1 1 1 0 = { 1 2 3 }
  10. 1 1 1 1 = { 1 2 3 4 }
  11.  
kind regards,

Jos
You wish everybody counted in binary too don't you?
Mar 28 '07 #3
JosAH
11,448 Expert 8TB
You wish everybody counted in binary too don't you?
:-) Well, it can come in handy now and then doesn't it?

kind regards,

Jos
Mar 28 '07 #4
r035198x
13,262 8TB
:-) Well, it can come in handy now and then doesn't it?

kind regards,

Jos
Some say it's the first sign of an addiction.


@OP You will need to put in a bit of work. The suggestion you got is as far we'll go until you put in some of your work.
Mar 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: les_ander | last post by:
Hi, I have many set objects some of which can contain same group of object while others can be subset of the other. Given a list of sets, I need to get a list of unique sets such that non of the...
29
by: Chris Dutrow | last post by:
I searched around on the net for a bit, couldn't find anything though. I would like to find some code for a function where I input A Range Of Integers For example: Function( 1, 100 ); And the...
2
by: Dave | last post by:
Hello all, I have a class that contains a large number of discrete pieces of state information. Any combination of these member variables might be valid for a given object. Any given member...
5
by: Dylan | last post by:
Is there an STL algorithm that will return true if each element in coll1 is present in coll2
5
by: sdowney717 | last post by:
Is there a way to construct a query to select for whole words only? select id from bookdata where titles like '%Test%' gets everything with test somewhere in the field. So you could get records...
7
by: Scott W Gifford | last post by:
Hello, I'm considering using XML to represent a stream of location information, and XPath to do queries against it. I've got most of it figured out (at least on paper), but I can't figure out...
36
by: Robert Vazan | last post by:
I am looking for other people's attempts to create safe subset of C and enforce it with scripts. Does anybody know about anything like this? By "safe", I mean the following: * Strongly typed...
32
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 *...
1
by: calvin | last post by:
Can anyone write a code for this? Searching a set of Integers You are given two sets of integers. S1 and S2. The size of S1 is less than sizeof S2, i.e. the number of integers in S1 is less...
1
by: jehugaleahsa | last post by:
Hello: Currently, I have a system that will use Regex to find tags in a string of HTML. Recently my company needs me to read the HTML dynamically from a stream, so as to avoid long waits on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.