generating all possible k partition of an array

Clash 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.
discrete-mathematics algorithms recursive-algorithms data-structure
add a comment |Â
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.
discrete-mathematics algorithms recursive-algorithms data-structure
add a comment |Â
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.
discrete-mathematics algorithms recursive-algorithms data-structure
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.
discrete-mathematics algorithms recursive-algorithms data-structure
asked Aug 21 at 8:38
Dharmendra Parmar
745
745
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited Aug 21 at 9:32
answered Aug 21 at 9:19
Sandro LovniÃÂki
1414
1414
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password