My problem is let suppose my dataset is {A,B,C,D,E}
and suppose my partition size is (2,3)
Result would be
(A,B) (C,D,E)
(A,C) (B,D,E)
(A,D) (C,B,E)
(A,E) (B,C,D)
(B,C) (A,D,E)
(B,D) (A,C,E)
(B,E) (A,C,D)
(C,D) (A,B,E)
(C,E) (A,B,D)
(D,E) (A,B,C)
I need to print all the possible combinations for the partition size provide...The partition size could be(1,4) also...

Please help me out with the logic. Thanks

5 Years
Discussion Span
Last Post by Taywin

What you need is all combinations of the set. Then the break down is done after you have all the combinations. If you notice how each element arranges in the solution, you would know what I mean.

Now, a link solution and explanation about how a combination works is at this one http://stackoverflow.com/questions/127704/algorithm-to-return-all-combinations-of-k-elements-from-n. You could see how it is done in various languages. Also, other people posted about disadvantages of each technique. Please do not just copy and paste the code portion you want but read everything on the page. It is very useful for you in the future.

Edited by Taywin: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.