Intuition
The core idea is to build the subsets incrementally using a recursive technique called **backtracking**. Imagine a decision tree. At each level of the tree, we are deciding whether to include the current number `nums[i]` in our subset or not.
- The Choice: For each element in `nums`, we have two choices: either **include** it in the current subset or **skip** it.
- Explore: We start with an empty subset. We then iterate through the `nums` array. For each number, we add it to our current subset and then recursively call our function to generate all further subsets that can be formed with this new addition.
- Backtrack: This is the crucial step. After the recursive call returns (meaning it has explored all possibilities with the number included), we **remove** that number from our current subset. This "backtracking" allows us to explore the path where the number was *not* included, enabling us to generate all possible combinations.
Step-by-Step Code
Live Visualization & Controls
Decision Tree
Result Subsets
Algorithm States
Call Stack
Stack is empty