Subsets
All about subsets
Definition
A subset of an array is a selection of elements (possibly none) of the array.
Generating Subsets
1. Recursive Calls
At each element, push one element into the array. Then make a recursive call to the function. After the call, pop out the element and continue to the next decision branch.
The logic behind this is that, at every point, there are only two possibilities: either include the element or not. So we make two recursive calls to include all cases.
2. Bit Manipulation
Use bit representation of the total number of possible subsets to push in corresponding elements into a subset. This can be implemented easily because of the binary decision for whether to put in an element, which matches the property of a binary bit.
Last updated