Obtaining a powerset of a set in Java

后端 未结 26 2116
青春惊慌失措
青春惊慌失措 2020-11-22 11:33

The powerset of {1, 2, 3} is:

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

Let\'s say I have a Set in Java:<

26条回答
  •  余生分开走
    2020-11-22 11:40

    Here is a tutorial describing exactly what you want, including the code. You're correct in that the complexity is O(2^n).

提交回复
热议问题