Example: Subset Sum (cont)
Generate and test approach:
subsetsum(A,k):
| Input set A of n integers, target sum k
| Output true if Σx∈Sx=k for some S⊆A
| false otherwise
|
| for each subset B⊆A do
| | if Σb∈Bb=k then
| | return true
| | end if
| end for
| return false
|
- How many subsets are there of n elements?
- How could we generate them?
|