What algorithm can calculate the power set of a given set?

Posted by ross on Stack Overflow See other posts from Stack Overflow or by ross
Published on 2010-05-06T06:58:41Z Indexed on 2010/05/06 7:18 UTC
Read the original article Hit count: 306

Filed under:
|

I would like to efficiently generate a unique list of combinations of numbers based on a starting list of numbers.

example start list = [1,2,3,4,5] but the algorithm should work for [1,2,3...n]

result =

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

Note. I don't want duplicate combinations, although I could live with them, eg in the above example I don't really need the combination [1,3,2] because it already present as [1,2,3]

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about powerset