find all subsets that sum to a particular value.
Given a set of numbers: {1, 3, 9, 12} and a target value = 12. find the distinct subset that sums to a target value.
ANS: [3,9], [12].
The problem has been asked here.
There are obviously two approaches to solve this kind of problem. Recursion or DP. Question: how do you trade off these two approaches?
My Solution: DP is harder but it consumes less memory. In recursion, you have to recursively call the function several times, this introduces functional over head. But it is "considerably" easier but consume more memory.
What do you guys think?