Given a set of elements, find all its subsets.
Best Case: Ω(n • 2ⁿ)
Average Case: θ(n • 2ⁿ)
Worst Case: O(n • 2ⁿ)
where n represents the size of the set.
Worst Case: O(n • 2ⁿ)
The function generate_subsets
has the following parameter(s):
a
: a vector of integers
Return value: a vector of vector of integers representing all the subsets.
The first line contains an integer n
, the size of array.
The next line contains n
space-separated integers a[i]
where 0 ≤ i
< n
.
2ⁿ lines denoting all possible subsets.
1
2
2
All possible subsets of {2}:
- {}
- {2}
2
11 13
11
13
11 13
All possible subsets of {11, 13}:
- {}
- {11}
- {13}
- {11, 13}
3
1 2 3
1
2
3
1 2
1 3
2 3
1 2 3
All possible subsets of {1, 2, 3}:
- {}
- {1}
- {2}
- {3}
- {1, 2}
- {1, 3}
- {2, 3}
- {1, 2, 3}