Class SubsetsGivenSum
java.lang.Object
topics.backtracking.SubsetsGivenSum
BACKTRACKING PROBLEM: SUBSETS OF A GIVEN SUM
This program, given a set consisting of n different positive
integers, computes all subsets which sum a given value c
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAn example: the first n natural numbersvoidAnother example: the first square numbersvoidbacktracking(int level) Performs the backtracking processintGets the number of solutions after the backtracking process
-
Constructor Details
-
SubsetsGivenSum
public SubsetsGivenSum(int n, int c) Constructor for SubsetsGivenSum objects- Parameters:
n- Number of elements for each casec- Sum that we are looking for
-
-
Method Details
-
assumption1
public void assumption1()An example: the first n natural numbers -
assumption2
public void assumption2()Another example: the first square numbers -
backtracking
public void backtracking(int level) Performs the backtracking process- Parameters:
level- Level in the tree of states starting at 0
-
getNumberOfSolutions
public int getNumberOfSolutions()Gets the number of solutions after the backtracking process- Returns:
- Number of solutions
-