0
4.3kviews
Solve sum of subsets problem for following N=6 W={3,5,7,8,9,15} & M=20 Also write the Algorithm for it.
1 Answer
1
118views

Problem:

We have n=6, W={3,5,7,8,9,15} & M=20

So the solution of the problem is shown below

enter image description here

Algorithm:

Sumofsub(s, k, r)

{

//generate left child

If(s+w[k]=m) then write (x(1:k));//subset found

else if (s+w[k]<=m)

then sumofsub(s+w[k], k+1, r-w[k]);

//generate right child and evaluate Bk

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

{

x[k]=0;

sumofsubset(s, k+1, r-w[k]);

}

}

Please log in to add an answer.