DP3: Subset Sum Revisited

San Skulrattanakulchai

October 11, 2018

Subset Sum Problem Revisited

Dynamic Programming Solution

Optimal Substructure Property

Recurrence

Subset Sum Algorithm

Running Time

Remarks

  1. The cases \(v=0\) and \(i=0\) in the recurrence are the so-called artificial base cases. For some problems, they help simplify the recurrence. For this particular problem, they don’t do much.
  2. Without using artificial base cases, we define \(m(i, v)\), for all \(1\le i \le n\) and \(1\le v\le t\), and the recurrence is \[ m(i, v) = \left\{ \begin{array}{ll} \mbox{true}, & \mbox{if $i=1$, $a_i=v$} \\ \mbox{false}, & \mbox{if $i=1$, $a_i\ne v$} \\ m(i-1,v), & \mbox{if $i>1$, $a_i>v$} \\ m(i-1,v-a_i) \vee m(i-1,v) & \mbox{if $i>1$, $a_i\le v$} \end{array} \right. \]
  3. If the set of numbers that add up to the target \(t\) is desired, we can get them from the filled-out \(M\) table directly without having to use an extra table.
  4. Instead of asking whether some subsequence of \(A\) summing to \(t\) exists, we can ask how many subsequences of \(A\) sum to \(t\) instead.
  5. Subset Sum is an NP-complete problem. (See DPV p.242.) Dynamic programming solves it in pseudo-polynomial time.
  6. The 0-1 Knapsack Problem is similar to the Subset Sum Problem. (See DPV p.164–167.)