Lecture16

# Lecture16 - Lecture 16 Subset Sum Given n positive integers...

This preview shows pages 1–3. Sign up to view the full content.

1 Subset Sum Given n positive integers x 1 , x 2 ,… x n and a number B Decide whether there is a subset S of them such that For example, if x ={1,5,7} and B =8, then S ={1,3} Brute force approach ? How about greedy approach ? NP-hard problem We will still try to solve, at least for cases where “B is small”. 191 ,{ 1 , , } i iS x BS n  Lecture 16, Nov 18 2010 Subset Sum – continued We will use Dynamic Programming How to choose subproblem ? Subproblem: » M(k,b)= true” iff there is a solution to » Result in M(n,B) » M(1,b)= true” iff x 1 =b , “false” otherwise. 192 ' ,' { 1 , , } i xS bk Goal:Find {1, , } . . i Sn s t x B 

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Subset Sum – continued Main recurrence: » M(k+1,b)=M(k,b) or M(k,b-x k+1 ). » Explanation: Either use x k+1 or do not use it » Use “false” for non-existing elements of M() . » Running time: Matrix M is [n x B], each element constant time: O(nB).
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

Lecture16 - Lecture 16 Subset Sum Given n positive integers...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online