All Topics

Backtracking

Systematic exploration of all possibilities — subsets, permutations, and constraint satisfaction

0/48 solved

Subsets

Generate all subsets (power set) of a given set

O(n * 2^n) O(n) recursion depth

Approach

At each recursive step, choose to include or exclude the current element. Build subsets incrementally by adding the current subset to results at every recursive call (not just at leaves).

How to Recognize

1

Problem asks for all subsets or combinations of elements

2

Need to generate the power set

3

Phrases like 'all possible subsets', 'subset sum'

4

Input has no duplicates (subsets I) or has duplicates (subsets II)

Pro Tips

For each element, two choices: include or exclude

For duplicates, sort first and skip consecutive equal elements at the same level

Total subsets = 2^n — be aware of exponential output

8

Total

0

Easy

8

Medium

0

Hard

Time

O(n * 2^n)

Space

O(n) recursion depth