How do you generate all subsets of an array using backtracking?

Updated Apr 28, 2026

Short answer

Use recursion to include/exclude each element.

Deep explanation

At each index, you have two choices: include the element or skip it. This forms a decision tree of size 2^n.

Real-world example

Generating all combinations of features.

Common mistakes

  • Not copying path (mutating result).

Follow-up questions

  • Time complexity?
  • Why start index?

More Backtracking interview questions

View all →