next up previous
Next: Up: Previous:

Subset-Sum Problem

Definition

Algorithm:



Exact-Subset-Sum(S, t) $\;\;\;\;\;$ $\;\;\;\;\;$; S = {x1, .., xn}
$\;\;\;\;\;$n = $\mid$S$\mid$
$\;\;\;\;\;$L0 = $\langle$0$\rangle$
$\;\;\;\;\;$for i = 1 to n
$\;\;\;\;\;$ $\;\;\;\;\;$Li = Merge-Lists( \(L_{i-1}, \;L_{i-1} \;+\; x_i\))
$\;\;\;\;\;$ $\;\;\;\;\;$remove from Li elements > t
$\;\;\;\;\;$return largest element in Ln



Example

S = {1, 2, 3}
L0 = $\langle$0$\rangle$
L1 = $\langle$0, 1$\rangle$
L2 = $\langle$0, 1, 2, 3$\rangle$
L3 = $\langle$0, 1, 2, 3, 4, 5, 6$\rangle$



Analysis


next up previous
Next: Up: Previous: