01Every subset is a path of decisions
To build a subset of {1, 2, 3}, make one decision per element: take it or skip it. Three yes/no decisions give 2 · 2 · 2 = 8 subsets. Draw the decisions as a binary tree: each level decides one element, each path from root to leaf is one subset.
Recursion walks this tree directly:
search(k): ifk == n, print the current subset;- otherwise call
search(k+1)withouta[k]; - then
push_back(a[k]), callsearch(k+1), andpop_back().
The pop_back() is essential: it undoes the choice so that the caller gets the subset back exactly as it was. Every leaf is visited once, so each subset is printed exactly once.