Professional Documents
Culture Documents
Pundra University of Science & Technology Rangpur Road, Gokul, Bogra-5800
Pundra University of Science & Technology Rangpur Road, Gokul, Bogra-5800
Rangpur Road,Gokul,Bogra-5800
Represent By
Md. Rakibul Hasan
Department: Computer Science & Engineering
Batch: 6th
Semester: 6th
Roll: 13
PRESENTATION TOPIC IS
“SUM OF SUBSET”
SUM OF SUBSET
Definition: Suppose we are given n distinct positive number (usually called
weights)and we desire to find all combination of theses numbers whose sums are
m, This called the sum of subset.
So
given n positive integers (weights) w1,
w2, ...,wn
given a positive integer W
finding all subsets of n integers that
sum to W
e.g., wi+wj+...+wk=W
SUM OF SUBSET
create a state space tree
each left edge denotes we include
wi(weight wi)
each right edge denotes we
exclude wi (weight 0)
any path from root to a leaf forms a
subset
SUM OF SUBSET
SUM OF SUBSET
Algorithm :SumofSub(s,k,r)
//Find all subset of w[1:n] that sum to m.The values of x[j],
//1<=j<k,have alredy been determined s=sum( k-1/j=1)w[j]*x[j]
//and r=sum(m/j-k)w[j].The w[j]’s are nondecreasing order.
//it is assumed that w[1]<=m and sum)(n/i=1)w[i]>=m.
{
//Generate left child .Note:s+w[k]<m since Bk-1 is true.
X[k]:=1
If(s+w[k]=m then write (x[1:k]);//subset found
//There is no recursive call here as w[j]>0,1<=j<=n
Else if(s+w[k]+w[k+1]<=m)
Then sumof sub(s+w[k],k+1,r-w[k]);
//Generate right child and evulate Bk continue to next page
SUM OF SUBSET
Consider input:
How many value in the set? 5
Enter value:3 5 6 7 8
Enter the amount of sum:18