subsets of array

J

Jessica Weiner

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
 
A

Alf P. Steinbach

* Jessica Weiner:
I have an array of n integers and I want a function that returns a list of
arrays of all possible subsets.

The number of possible subsets is exponential in n: how much memory do
you think that will require?

Since this is obviously HOMEWORK (see this group's FAQ before posting,
please) I'll leave it to you to figure out exactly what the formula is.

It's probably also stated in your textbook.

Can someone provide me with the code?

Yes, but /will/ someone do your HOMEWORK for you?

Hopefully not.

See the FAQ's item about posting HOMEWORK questions.
 
J

Jessica Weiner

Alf said:
Since this is obviously HOMEWORK (see this group's FAQ before posting,
please) I'll leave it to you to figure out exactly what the formula
is.

Its not homework, you dumbass. If you cannot help someone then simply keep
your mouth shut because it only goes to show how stupid you are.
 
D

Default User

Jessica Weiner wrote:

Its not homework, you dumbass. If you cannot help someone then simply
keep your mouth shut because it only goes to show how stupid you are.



Wow, very speedy in getting into the old killfile.


*plonk*



Brian
 
D

dragoncoder

Jessica said:
Its not homework, you dumbass. If you cannot help someone then simply keep
your mouth shut because it only goes to show how stupid you are.

Stupid ?? Do you know who you are talking to ?
 
B

BigBrian

Jessica said:
I am talking to Stupid...... STUPID.

Boy, that attitude will really get you what you asked.

Even if your original post wasn't about homework, asking for "code that
does [insert whatever here]" that is not what this group is about.
Calling somebody stupid is even less what it's about. When you have a
C++ question, or C++ topic to discouss, come back, otherwise go away.
 
S

Salt_Peter

Jessica Weiner said:
I am talking to Stupid...... STUPID.

If he is stupid as you claim then try conducting a simple search on he who
you are calling stupid. You'll be surprised ( i guarentee it! ). Then
consider what "class" we should put you in since everything is relative,
after all.

My 8 year-old nephew can generate a better structured question than the
ridiculous quest you put forth. Additionally, if you can't serve yourself
nor gain a little maturity then... GROW UP, ASSHOLE !!!
 
B

BobR

BigBrian wrote in message ...
Jessica said:
I am talking to Stupid...... STUPID.

Boy, that attitude will really get you what you asked.

Even if your original post wasn't about homework, asking for "code that
does [insert whatever here]" that is not what this group is about.
Calling somebody stupid is even less what it's about. When you have a
C++ question, or C++ topic to discouss, come back, otherwise go away.


Now Brian, don't be so short(yup, a pun). If they want code, give them code:

#include <iostream> // C++
#include <ostream> // std::endl

void Weiner(int array = 43){
std::cout<<"33 33 33 75 78 79 76 80 32 33 101 114 "
"101 104 32 112 108 101 104 32 111 110 "
"32 115 116 101 103 32 101 100 117 116 "
"105 116 116 97 32 110 97 32 104 116 105 "
"119 32 116 111 105 100 105 32 110 65 "<<std::endl;
Weiner(array+1);
return;
}

int main(){
Weiner(42);
return 0;
}
 
L

lichaoji

BobR said:
BigBrian wrote in message ...
Jessica said:
dragoncoder wrote:
Stupid ?? Do you know who you are talking to ?

I am talking to Stupid...... STUPID.

Boy, that attitude will really get you what you asked.

Even if your original post wasn't about homework, asking for "code that
does [insert whatever here]" that is not what this group is about.
Calling somebody stupid is even less what it's about. When you have a
C++ question, or C++ topic to discouss, come back, otherwise go away.


Now Brian, don't be so short(yup, a pun). If they want code, give them code:

#include <iostream> // C++
#include <ostream> // std::endl

void Weiner(int array = 43){
std::cout<<"33 33 33 75 78 79 76 80 32 33 101 114 "
"101 104 32 112 108 101 104 32 111 110 "
"32 115 116 101 103 32 101 100 117 116 "
"105 116 116 97 32 110 97 32 104 116 105 "
"119 32 116 111 105 100 105 32 110 65 "<<std::endl;
Weiner(array+1);
return;
}

int main(){
Weiner(42);
return 0;
}

The most wonderful code I read today.
 
A

Alex Buell

I am talking to Stupid...... STUPID.

Oh yes! You're one of these women who thinks using their bodies will
get them anything they want. Well, HELLO! <sfx: knocks on your head>
You won't get what you want from here. We Nerds (let's not forget about
the Geeks either), have suffered enough at the hands of women like you.

ENOUGH is ENOUGH!

It's time we had Men's Lib, just to balance things out a little bit!
 
T

Tomás

Jessica Weiner posted:
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?

No, but I can give you a hand.


First start of with an array full of zeros:

unsigned array[5] = {};

Then increment the last int, so you have:

0 0 0 0 1

That's one of your arrays. Keep incrementing it until you reach the maximum
value for an unsigned int. The set it to zero and increment the int behind,
as follows:

0 0 0 0 65535

will become:

0 0 0 1 0

Then when that reaches:

0 0 0 65535 65535

Increment the one behind both of them, giving:


0 0 1 0 0


And that will eventually become:


0 0 65535 65535 65535



It would require a lot of memory to do this. I'm not a mathematician, but
maybe someone knows the equation to figure out how much.

If you want answers here, it's best to be polite.

-Tomás
 
J

Jessica Weiner

Salt_Peter said:
If he is stupid as you claim then try conducting a simple search on
he who you are calling stupid. You'll be surprised ( i guarentee it!
).

When you are done sucking his dick, maybe then you can come talk to me and I
will have a more "structured" comment for you.

A simple google search on "Alf Steinbach" doesn't reveal anything
spectacular. It only shows that he has been active on the newsgroups for a
while, which makes me think that he doesnt have a real job so he wanders
around from newsgroup to newsgroup trying to get jerks like yourself to
respect him.

I feel sorry for your nephew to have such a stupid uncle.

~Jessica
 
J

Jessica Weiner

Tomás said:
It would require a lot of memory to do this. I'm not a mathematician,
but maybe someone knows the equation to figure out how much.

Thanks!
 
T

Tomás

NumberType *p = new NumberType[ very_big_number ];
//Ask a mathematician how to calculate very_big_number


Actually it just occurred to me how to calculate this.

The "smallest" possibility will be:

0 0 0 0 0


And the largest possibility will be:


65535 65535 65535 65535 65535


If we think of this as a number system whose base is 65536, rather than 10,
and then give the digit 65535 the symbol K, then the number is:

KKKKK

If we want to convert that to decimal (base 10), then we use the following
formula:

65535 x 65535^0
+ 65535 x 65535^1
+ 65535 x 65535^2
+ 65535 x 65535^3
+ 65535 x 65535^4

So... if you have fives 16-Bit numbers, then "very_big_number" is a HUGE
number, something like a quadilion-trillion-gaziliion-mammillion-billion.

Best to use just a few 8-Bit numbers.


-Tomás
 
M

Markus Schoder

Tomás said:
NumberType *p = new NumberType[ very_big_number ];
//Ask a mathematician how to calculate very_big_number


Actually it just occurred to me how to calculate this.

The "smallest" possibility will be:

0 0 0 0 0


And the largest possibility will be:


65535 65535 65535 65535 65535


If we think of this as a number system whose base is 65536, rather than 10,
and then give the digit 65535 the symbol K, then the number is:

KKKKK

If we want to convert that to decimal (base 10), then we use the following
formula:

65535 x 65535^0
+ 65535 x 65535^1
+ 65535 x 65535^2
+ 65535 x 65535^3
+ 65535 x 65535^4

So... if you have fives 16-Bit numbers, then "very_big_number" is a HUGE
number, something like a quadilion-trillion-gaziliion-mammillion-billion.

Best to use just a few 8-Bit numbers.

It seems you are trying to enumerate all possible sets of integers with
a given number of elements whereas the original question was about the
subsets of a given set of integers (represented as an array), no?

E.g. the result for {1,2} would be the list {}, {1}, {2}, {1,2}. There
are by the way 2^n subsets of a set with n elements.
 
B

BobR

(e-mail address removed) wrote in message ...
The most wonderful code I read today.

Glad to see I'm not alone in the "need to get a life" catagory! <G>

[ we get *excited* when they say "stay tuned for scenes" at the end of
NCIS/CSI tv programs!! Wish sombody would send me a beer.]
 
M

Markus Schoder

A simple google search on "Alf Steinbach" doesn't reveal anything
spectacular. It only shows that he has been active on the newsgroups for a
while, which makes me think that he doesnt have a real job so he wanders
around from newsgroup to newsgroup trying to get jerks like yourself to
respect him.

Googling for a name is a good idea. It is actually such a good idea
that many employers do it with the names of job applicants. So I think
you have provided a valuable service to any potential future employer
that will now be able to easily figure out what kind of person you are
by googling your name and finding your posts in this newsgroup.
 
J

Jessica Weiner

Jessica said:
Googling for a name is a good idea. It is actually such a good idea
that many employers do it with the names of job applicants. So I think
you have provided a valuable service to any potential future employer
that will now be able to easily figure out what kind of person you are
by googling your name and finding your posts in this newsgroup.

And that is why strippers use fake names. Think of me as a usenet stripper.

~Jessica
(yeah right)
 
F

Fei Liu

Jessica said:
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

The number of possible combinations are:
sigma(n!/((n-i)!*i!), i = 1, n-1) + 1

You can write a code to translate this algorithm to generate subsets.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top