k-combinations of a set of integers in ascending size order

Posted by Adamski on Stack Overflow See other posts from Stack Overflow or by Adamski
Published on 2010-04-08T11:43:56Z Indexed on 2010/04/08 12:03 UTC
Read the original article Hit count: 266

Filed under:
|

Programming challenge: Given a set of integers [1, 2, 3, 4, 5] I would like to generate all possible k-combinations in ascending size order in Java; e.g.

[1], [2], [3], [4], [5], [1, 2], [1, 3] ... [1, 2, 3, 4, 5]

It is fairly easy to produce a recursive solution that generates all combinations and then sort them afterwards but I imagine there's a more efficient way that removes the need for the additional sort.

© Stack Overflow or respective owner

Related posts about java

Related posts about algorithm