Choose, explore, and undo
Generate decisions without letting one branch contaminate the next.
Understand the idea
Backtracking extends a partial candidate, explores its completions, and restores temporary state before trying a sibling. To generate subsets, make one take-or-skip decision per input position. To generate binary strings, append one symbol, recurse, then remove it.
Trace a small example
For [A, B], decisions produce {}, {B}, {A}, and {A, B}. These are subsets of positions: two equal input values can still represent different choices. A shared vector must lose the item added by a branch before that branch returns.
Conditions and cost
There are 2^n subsets. Copying or printing each may add O(n) work per result. Store only the current path unless all answers are required in memory. Do not stop a counting task merely because the current sum already matches a target.
Why is pop_back needed after exploring an appended choice?
Turn the idea into code
List all index subsets of [5, 5].
Give me a hint
Name the two positions A and B even though their values match.
Show the explained solution
The four subsets are {}, {A}, {B}, and {A, B}. The two one-element subsets are distinct position choices.
Your notes
Mark complete when you can explain it yourself.