BacktrackingAnimated
Subset Generation
For each item choose include or exclude.
Time
O(2ⁿ · n)
Extra space
O(n)
Use it for
Power set enumeration.
How it works
- For every element there are two choices: include it or leave it out.
- Recurse down the list making one choice per element.
- When every element has been decided, the choices made so far form one subset. Record it.
- Then backtrack: undo the last choice and try the other branch. 2ⁿ subsets in total.
Watch it run
Loading animation…