0

Given:

{1,2,3} 

Expected result:

{1,2,3}, {1,2},{1,3},{2,3}, {1},{2},{3} 

So I want basically ALL possible combinations in a list ( but including all possible combinations of - when every element is removed ).

I hope you get what I mean ;)

Question: Which algorithm achieves this?

3
  • 4
    Anonymous downvotes, gotta love ’em. Commented Apr 6, 2013 at 16:35
  • 2
    It's the power set algorithm. Commented Apr 6, 2013 at 16:42
  • You may want to read "Introduction to Algorithms", any sophisticated library will have that in stock. Commented Apr 6, 2013 at 16:50

1 Answer 1

4

You want the power set algorithm.

There are some examples on Rosetta Code.

Sign up to request clarification or add additional context in comments.

2 Comments

You could at least copy-paste C# code from that site ... Otherwise it's more like a comment, not an answer.
@MarcinJuraszek Thanks for your comment, I was just about to start writing a python recursive function which does this... :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.