Algorithm:SumOfSub(s,k,r)

//Finfd all subset of W[1:n] that sum to m.The values

//of x[j]; 1<=j<k, have already been determined.

* s = ∑

// The w[j]'s are in non decreasing order.

//It is assumed that W[1] <= m and ∑

{

// Generate left child .Note that s+w[k] <= m

//because B

//Finfd all subset of W[1:n] that sum to m.The values

//of x[j]; 1<=j<k, have already been determined.

* s = ∑

^{k-1}_{j=1>}W[j] * x[j] and r = ∑^{n}_{j=k>}W[j]// The w[j]'s are in non decreasing order.

//It is assumed that W[1] <= m and ∑

^{ni=1}_{>}W[i] ≥ m{

// Generate left child .Note that s+w[k] <= m

//because B

_{k-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 SumOfSub(s+w[k], k+1, r-w[k]);}_{//Generate right child and evaluate Bk-1}_{if((s+r-w[k] >=m) && (s+w[k+1] <=m)) then {}_{x[k] = 0;}_{SumOfSub(s, k+1, r-w[k]); }