Module 9 · Backtracking · Backtracking: Inclusion–Exclusion

Subsets II

The AvailableBox groups equal numbers: one place per value, holding all its copies. A call buildSubSets(nextUnique) decides one value: it adds one copy to currentList and goes deeper, adds another and goes deeper again, then puts them all back (removeLastK) and goes deeper with none. Equal numbers are never picked in two different orders, so no subset repeats. In the tree a box shows the list a call starts from, a branch shows what was added or skip, and every leaf adds one subset.