generating all possible k partition of an array

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












actually, I confronted a problem for generating all possible k partitions of an array. I tried to write the algorithm but actually, I am not able to.



can anybody please give me the idea, how to code this problem ?



for example



suppose I am given an array A = 1, 2, 3, 4, 5
and k = 3, then I have to write the code for all possible partition for k =3.
in this example, our all possible partitions are for k =3 is as follows

1, 2, 3, 4, 5

1, 2, 3, 4, 5

1, 2, 3, 4, 5

1, 2, 3, 4, 5

1, 2, 3 , 4, 5

1, 2, 3, 4, 5



thanks,
any effort is appreciatable.







share|cite|improve this question
























    up vote
    0
    down vote

    favorite












    actually, I confronted a problem for generating all possible k partitions of an array. I tried to write the algorithm but actually, I am not able to.



    can anybody please give me the idea, how to code this problem ?



    for example



    suppose I am given an array A = 1, 2, 3, 4, 5
    and k = 3, then I have to write the code for all possible partition for k =3.
    in this example, our all possible partitions are for k =3 is as follows

    1, 2, 3, 4, 5

    1, 2, 3, 4, 5

    1, 2, 3, 4, 5

    1, 2, 3, 4, 5

    1, 2, 3 , 4, 5

    1, 2, 3, 4, 5



    thanks,
    any effort is appreciatable.







    share|cite|improve this question






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      actually, I confronted a problem for generating all possible k partitions of an array. I tried to write the algorithm but actually, I am not able to.



      can anybody please give me the idea, how to code this problem ?



      for example



      suppose I am given an array A = 1, 2, 3, 4, 5
      and k = 3, then I have to write the code for all possible partition for k =3.
      in this example, our all possible partitions are for k =3 is as follows

      1, 2, 3, 4, 5

      1, 2, 3, 4, 5

      1, 2, 3, 4, 5

      1, 2, 3, 4, 5

      1, 2, 3 , 4, 5

      1, 2, 3, 4, 5



      thanks,
      any effort is appreciatable.







      share|cite|improve this question












      actually, I confronted a problem for generating all possible k partitions of an array. I tried to write the algorithm but actually, I am not able to.



      can anybody please give me the idea, how to code this problem ?



      for example



      suppose I am given an array A = 1, 2, 3, 4, 5
      and k = 3, then I have to write the code for all possible partition for k =3.
      in this example, our all possible partitions are for k =3 is as follows

      1, 2, 3, 4, 5

      1, 2, 3, 4, 5

      1, 2, 3, 4, 5

      1, 2, 3, 4, 5

      1, 2, 3 , 4, 5

      1, 2, 3, 4, 5



      thanks,
      any effort is appreciatable.









      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Aug 21 at 8:38









      Dharmendra Parmar

      745




      745




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          If we look closely at the problem, the only thing to determine here is the $k-1$ places in the array where to put "breaks" to separate it into $k$ sets. You can generate all those combinations with nested loops or recursion. For reference, see Stars and Bars.



          Is it maybe that one such partition you are looking for would also be, say
          $$2,3,4,5,1?$$



          If yes, then you will also need to generate all permutations of an array before doing the stars and bars. You can generate all permutations with Heap's algorithm.






          share|cite|improve this answer






















            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "69"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2889620%2fgenerating-all-possible-k-partition-of-an-array%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            If we look closely at the problem, the only thing to determine here is the $k-1$ places in the array where to put "breaks" to separate it into $k$ sets. You can generate all those combinations with nested loops or recursion. For reference, see Stars and Bars.



            Is it maybe that one such partition you are looking for would also be, say
            $$2,3,4,5,1?$$



            If yes, then you will also need to generate all permutations of an array before doing the stars and bars. You can generate all permutations with Heap's algorithm.






            share|cite|improve this answer


























              up vote
              1
              down vote













              If we look closely at the problem, the only thing to determine here is the $k-1$ places in the array where to put "breaks" to separate it into $k$ sets. You can generate all those combinations with nested loops or recursion. For reference, see Stars and Bars.



              Is it maybe that one such partition you are looking for would also be, say
              $$2,3,4,5,1?$$



              If yes, then you will also need to generate all permutations of an array before doing the stars and bars. You can generate all permutations with Heap's algorithm.






              share|cite|improve this answer
























                up vote
                1
                down vote










                up vote
                1
                down vote









                If we look closely at the problem, the only thing to determine here is the $k-1$ places in the array where to put "breaks" to separate it into $k$ sets. You can generate all those combinations with nested loops or recursion. For reference, see Stars and Bars.



                Is it maybe that one such partition you are looking for would also be, say
                $$2,3,4,5,1?$$



                If yes, then you will also need to generate all permutations of an array before doing the stars and bars. You can generate all permutations with Heap's algorithm.






                share|cite|improve this answer














                If we look closely at the problem, the only thing to determine here is the $k-1$ places in the array where to put "breaks" to separate it into $k$ sets. You can generate all those combinations with nested loops or recursion. For reference, see Stars and Bars.



                Is it maybe that one such partition you are looking for would also be, say
                $$2,3,4,5,1?$$



                If yes, then you will also need to generate all permutations of an array before doing the stars and bars. You can generate all permutations with Heap's algorithm.







                share|cite|improve this answer














                share|cite|improve this answer



                share|cite|improve this answer








                edited Aug 21 at 9:32

























                answered Aug 21 at 9:19









                Sandro Lovnički

                1414




                1414






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2889620%2fgenerating-all-possible-k-partition-of-an-array%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    這個網誌中的熱門文章

                    tkz-euclide: tkzDrawCircle[R] not working

                    How to combine Bézier curves to a surface?

                    1st Magritte Awards