Get all subsets of a collection

后端 未结 7 568
青春惊慌失措
青春惊慌失措 2021-01-13 17:05

I am trying to create a method that will return all subsets of a set.

For example if I have the collection 10,20,30 I will like to get the following ou

相关标签:
7条回答
  • 2021-01-13 17:40

    This is a basic algorithm which i used the below technique to make a single player scrabble word solver (the newspaper ones).

    Let your set have n elements. Increment an integer starting from 0 to 2^n. For each generater number bitmask each position of the integer. If the i th position of the integer is 1 then select the i th element of the set. For each generated integer from 0 to 2^n doing the above bitmasting and selection will get you all the subsets.

    Here is a post: http://phoxis.org/2009/10/13/allcombgen/

    0 讨论(0)
提交回复
热议问题