Power Set

Power Set:

The power set (or powerset) of any set S is the set of all subsets of S, including the empty set and S itself.

Solution:

• Recursive Algorithm: A Power set of P(n) can be computer from P(n-1) by added nth element in each set of P(n-1)
• Iterative Algorithm: Based on binary representation
Recursive Algorithm:
1. If `index == set.size` then
1. Create setsOfSet
2. Add empty set to setsOfSet1
2. Else
1. Recursively call with index + 1
2. get ithElement from Set
3. Create empty setsOfSet2
4. Iterate all sets S for setsOfSet1
1. Create newSet
2. Add elements of set S to newSet
5. Add all sets setsOfSet2 to setsOfSet1
3. Return setsOfSet1
Iterative Algorithm:
1. Compute totalNumberSubset i.e 2^set.size
2. Iterate 0 to totalNumberSubset
1. Covert each number to binary representation
2. Create subset based on binary representation

Latest Source Code:
Github: PowerSet.java

Output:

```Power of [1, 3, 2] (Recursive): [[], [2], [3], [2, 3], [1], [2, 1], [3, 1], [2, 3, 1]]
Power of [1, 3, 2] (Iterative): [[], [1], [3], [1, 3], [2], [1, 2], [3, 2], [1, 3, 2]]
```
Author: