Backtracking
Decision Tree Visualizer
Step through choose, explore, reject, and undo moments while the path, board state, result count, time, and space complexity update.
O(2^n) time / O(n) space
Choices
Choice1
Choice2
Choice3
Current Path
empty
Results
No result yet
Results
0
Time
O(2^n)
Space
O(n)
Step Note
Start with an empty subset path.
function subsets(values: number[]) {
const result = []
function dfs(index: number, path: number[]) {
if (index === values.length) result.push([...path])
path.push(values[index])
dfs(index + 1, path)
path.pop()
dfs(index + 1, path)
}
dfs(0, [])
return result
}