Subsets
Question (LC.78)
Example
I: [1,2,3]
O: [ [],
[1], [2], [3],
[1,2], [1,3],
[2,3],
[1,2,3]
]Exhaustive Search (prefix tree)
Define Recursion
genSubsets(List<List<Integer>> results, int[] nums, List<Integer> subset, int startIndex)
startIndex is a starting node for this depth first search
Add all susbets starting with startIndex with subset as prefix to results
Recursive Calls
for i from startIndex to n-1
genSubsets(results, nums, new subset.add(i), i+1)
Base Case
if startIndex = n: results.add(new subset)Code
Exhaustive Search (decision tree)
Code
Binary Number
Code
Time Complexity
Follow Up (LC.90)
Example
Analysis
Prune Decision Tree
Prune Prefix Tree
Last updated