Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 4: Subset sums Define a class A5Q4 which contains only the following two static methods (no objects) Warning: This is a more difficult recursion,

image text in transcribed

Question 4: Subset sums Define a class A5Q4 which contains only the following two static methods (no objects) Warning: This is a more difficult recursion, which many students will find challenging Define a recursive methood static ArrayList subsetWithSum(ArrayList numbers, int sum) which will accept an ArrayList numbers containing only integer values greater than 0, and an integer sum. It should try to find a combination of the integers in the list that add up to the required sum. Each integer in the list may be used only once. There will be no duplicate integers in the list. There might be more than one way to make the required sum, but you only have to find and return one of them. An ArrayList containing the integers that form the required sum should be returned. If there is no way to make the required sum with the available integers, null should be returned. This method must not destroy the parameter numbers. For example, the test code ArrayList answer- subsetWithSum(test, sum); System.out.println(sum+" can be made with: "+answer); should produce the output Available numbers: [3, 11, 1, 5] 16 can be made with: [11, 5] 17 can be made with: [11, 1, 5] 18 can be made with: null 19 can be made with: [3, 11, 5] Define a main method which will use the list above ([3, 11,1, 5]) to try to make every sum from 1 to 21

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions