Skip to main content

Algorithm for Sum of Subset


Algorithm Subset(set[] ,n ,sum) { //Base Case if(sum=0) { return true; } else if(n=0 && sum!=0) then, { return false; } else if(set[n-1]>sum) then, { //when the element is greater than Sum return Subset(set,n-1,sum); } else { return Subset(set,n-1,sum) or Subset(set,n-1,sum-set[n-1]); } }

Posted by -