A subset of elements can be represented as an -bit integer. Bit is if element is included.
for mask from 0 to 2^n - 1:
subset = []
for i from 0 to n-1:
if mask & (1 << i):
subset.add(elements[i])
// process subset
Example: , elements .
- mask (binary ):
- mask (binary ):
- mask (binary ):
- mask (binary ):
Time: . Generate all subsets, each takes to process.