CSCI 605 Week 1 Assignment 2 solution

$25.00

Original Work ?
Category:

Description

5/5 - (4 votes)

Your assignment is to write a program that can determine if given a set of numbers, is there a subset that sums to 0?

 

Your sets may be hardcoded.

 

Your solution should be general enough that if the set is changed either in content or volume, your algorithm should still work as intended.

 

An example main method might look like the following,

 

 

public static void main( String[] arguments )
{
int[] testSet = { -1, -1, 2, 5, 6 };
int[] testSet2 = { -1, 2, 2 };

System.out.println(“Checking ” + Arrays.toString(testSet) + ” – should be ” + true);
checkSet(testSet);
System.out.println(\nChecking ” + Arrays.toString(testSet2) + ” – should be ” + false);
checkSet(testSet2);
}

 

The output of the above code may look like the following,

 

Checking [-1, -1, 2, 5, 6] – should be true

Found subset that sums to zero: -1 -1 2

 

Checking [-1, 2, 2] – should be false

Unable to find subset that sums to zero

 

Your solution should be named Zero.java

 

You can only use basic types.

 

You may not use and existing classes that may solve part or all of this problem for you.

 

Grading:
Correctness: You can lose up to 20% if your solution is not correct
Quality: You can lose up to 20% if your solution is poorly designed
Testing: You can lose up to 20% if your solution is not well tested
Explanation: You can lose up to 40% if you cannot explain your solution during the grading session