subsets of array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jessica Weiner

    subsets of array

    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


  • Alf P. Steinbach

    #2
    Re: subsets of array

    * Jessica Weiner:[color=blue]
    > I have an array of n integers and I want a function that returns a list of
    > arrays of all possible subsets.[/color]

    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.

    [color=blue]
    > Can someone provide me with the code?[/color]

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

    Hopefully not.

    See the FAQ's item about posting HOMEWORK questions.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?

    Comment

    • Jessica Weiner

      #3
      Re: subsets of array

      Alf P. Steinbach wrote:[color=blue]
      > 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.[/color]

      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.


      Comment

      • Default User

        #4
        Re: subsets of array

        Jessica Weiner wrote:

        [color=blue]
        > 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.[/color]



        Wow, very speedy in getting into the old killfile.


        *plonk*



        Brian

        Comment

        • dragoncoder

          #5
          Re: subsets of array


          Jessica Weiner wrote:[color=blue]
          > Alf P. Steinbach wrote:[color=green]
          > > 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.[/color]
          >
          > 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.[/color]

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

          Comment

          • Jessica Weiner

            #6
            Re: subsets of array

            dragoncoder wrote:[color=blue]
            > Stupid ?? Do you know who you are talking to ?[/color]

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


            Comment

            • BigBrian

              #7
              Re: subsets of array


              Jessica Weiner wrote:[color=blue]
              > dragoncoder wrote:[color=green]
              > > Stupid ?? Do you know who you are talking to ?[/color]
              >
              > I am talking to Stupid...... STUPID.[/color]

              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.

              Comment

              • Salt_Peter

                #8
                Re: subsets of array


                "Jessica Weiner" <jessica@gmail. com> wrote in message
                news:jra2g.1842 0$tN3.12058@new ssvr27.news.pro digy.net...[color=blue]
                > dragoncoder wrote:[color=green]
                > > Stupid ?? Do you know who you are talking to ?[/color]
                >
                > I am talking to Stupid...... STUPID.
                >
                >[/color]

                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 !!!


                Comment

                • BobR

                  #9
                  Re: subsets of array


                  BigBrian wrote in message ...[color=blue]
                  >
                  >Jessica Weiner wrote:[color=green]
                  >> dragoncoder wrote:[color=darkred]
                  >> > Stupid ?? Do you know who you are talking to ?[/color]
                  >>
                  >> I am talking to Stupid...... STUPID.[/color]
                  >
                  >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.[/color]


                  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::end l;
                  Weiner(array+1) ;
                  return;
                  }

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

                  --
                  Bob R
                  POVrookie


                  Comment

                  • lichaoji@gmail.com

                    #10
                    Re: subsets of array



                    BobR wrote:[color=blue]
                    > BigBrian wrote in message ...[color=green]
                    > >
                    > >Jessica Weiner wrote:[color=darkred]
                    > >> dragoncoder wrote:
                    > >> > Stupid ?? Do you know who you are talking to ?
                    > >>
                    > >> I am talking to Stupid...... STUPID.[/color]
                    > >
                    > >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.[/color]
                    >
                    >
                    > 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::end l;
                    > Weiner(array+1) ;
                    > return;
                    > }
                    >
                    > int main(){
                    > Weiner(42);
                    > return 0;
                    > }
                    >
                    > --
                    > Bob R
                    > POVrookie[/color]

                    The most wonderful code I read today.

                    Comment

                    • Tomás

                      #11
                      Re: subsets of array

                      Jessica Weiner posted:
                      [color=blue]
                      > 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?[/color]

                      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

                      Comment

                      • Alex Buell

                        #12
                        Re: subsets of array

                        On Fri, 21 Apr 2006 19:32:31 GMT "Jessica Weiner" <jessica@gmail. com>
                        waved a wand and this message magically appeared:
                        [color=blue]
                        > dragoncoder wrote:[color=green]
                        > > Stupid ?? Do you know who you are talking to ?[/color]
                        >
                        > I am talking to Stupid...... STUPID.[/color]

                        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!

                        --


                        Take a nap, it saves lives.

                        Comment

                        • Jessica Weiner

                          #13
                          Re: subsets of array

                          Salt_Peter wrote:[color=blue]
                          > 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!
                          > ).[/color]

                          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


                          Comment

                          • Jessica Weiner

                            #14
                            Re: subsets of array

                            Tomás wrote:[color=blue]
                            > 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.[/color]

                            Thanks!


                            Comment

                            • Tomás

                              #15
                              Re: subsets of array

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


                              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_numbe r" is a HUGE
                              number, something like a quadilion-trillion-gaziliion-mammillion-billion.

                              Best to use just a few 8-Bit numbers.


                              -Tomás


                              Comment

                              Working...