Skip to content

nikhildsahu/sum-of-subset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sum of Subset Problem

Implementation of this Backtracking Algorithm in JavaScript

CodeFactor

About

  • DAA Assignment for Sum of Subset Problem .

Sum Of Subset Problem

  • Sum of Subset problem is to find Subset of elements from a given Set whose Sum adds up to a given number K.
  • Set Contains non-negative values.

Algorithm

  • SubsetFind(set, subset, n, subSize, total, node, sum)

    • Input : Given Set , Subset, Size of Set & Subset , Total Sum of Subset , No of Elements in Subset , Required Sum
    • Output : Display all possible Subset present .
    Begin
      if total = sum, then
         display the subset
        //try for other subsets
        subsetSum(set, subset,n, subSize-1, total-set[node], node+1, sum)
        return
      else
        for all element i in the set, do  // select node 
           subset[subSize] := set[i]
            subSetSum(set, subset, n, subSize+1, total+set[i], i+1, sum)
         done
     End
    

How to Use

  • Input Set elements in first box (separated by , (comma) )
  • Input Sum Value in second box
  • Click Find Solution
  • Will get all Solution in third box.

Demo

Author

Nikhil Sahu - @nikhildsahu

https://nikhilsahu.me/