Example:
S = {x, y, z}
P(S) = {Ø, {x}, {y}, {z}, {x,y}, {x,z}, {y,z}, {x,y,z}}
Algorithm:
Setup:
- n: size of the original set
- 2ⁿ: size of the power set
- A: original set as an array with numbered indices 0 to n - 1
- P(S): power set to be created
Iterative loop algorithm:
- Loop i from 0 to < 2ⁿ
- Create empty temporary Set
- Loop j from 0 to < n
- If the jᵗʰ bit of the i counter is set, add A[j] to temporary Set
- Add temporary set to power set
Time complexity: O(n2ⁿ)
Reference: http://www.geeksforgeeks.org/power-set/