0% found this document useful (0 votes)
43 views10 pages

Pundra University of Science & Technology Rangpur Road, Gokul, Bogra-5800

The document describes the sum of subset problem, which involves finding all combinations of numbers from a set that sum to a given total. It provides an algorithm called SumofSub that recursively generates all possible subsets by including or excluding each number at each step. The algorithm is demonstrated with an example input of 5 numbers totaling 18.

Uploaded by

rakibul hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views10 pages

Pundra University of Science & Technology Rangpur Road, Gokul, Bogra-5800

The document describes the sum of subset problem, which involves finding all combinations of numbers from a set that sum to a given total. It provides an algorithm called SumofSub that recursively generates all possible subsets by including or excluding each number at each step. The algorithm is demonstrated with an example input of 5 numbers totaling 18.

Uploaded by

rakibul hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PUNDRA UNIVERSITY OF SCIENCE & TECHNOLOGY

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

If((s+r-w[k]>=m) && (s+w[k+1]<=m)) then


{
X[k]=0;
Sumof sub=(s,k+1,r-w[k]);
}
}
SUM OF SUBSET
Program of sumofsub using C++
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

Consider the result:


1.3+7+8=18
2.5+6+7=18
THANK YOU.

You might also like