Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.89 KB

README.md

File metadata and controls

54 lines (41 loc) · 1.89 KB

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/