Question & Answer: St 0 1 2 3 45 6 7 8 9 10 11 12 S[02 10 10 00 0 0 0 0 0 00 S[1 31 0 11 01 0 0 0 0 0 00 S[251 0 11 02 0 1 1 0 0 00 S[371 0 1 1 02 0…..

I have written a dynamic programming algorithm that finds the total amount of subsets that sum up to a target value. However, I am having trouble developing a function to recover the solution (that is, print out the actual subsets).

For example, let’s take the set [2,3,5,7,9] with the target 12. My algorithm calculates that there are 3 subsets. The output table is shown in the image below.

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: St 0 1 2 3 45 6 7 8 9 10 11 12 S[02 10 10 00 0 0 0 0 0 00 S[1 31 0 11 01 0 0 0 0 0 00 S[251 0 11 02 0 1 1 0 0 00 S[371 0 1 1 02 0…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

St 0 1 2 3 45 6 7 8 9 10 11 12 S[02 10 10 00 0 0 0 0 0 00 S[1 31 0 11 01 0 0 0 0 0 00 S[251 0 11 02 0 1 1 0 0 00 S[371 0 1 1 02 0 2112 02 S49 10 11 02 0 2 12 2 13

But, with more complicated solutions, how would I use my output table to recursively recover a solution? Any assistance is appreciated.

St 0 1 2 3 45 6 7 8 9 10 11 12 S[02 10 10 00 0 0 0 0 0 00 S[1 31 0 11 01 0 0 0 0 0 00 S[251 0 11 02 0 1 1 0 0 00 S[371 0 1 1 02 0 2112 02 S49 10 11 02 0 2 12 2 13

Expert Answer

 

Without your dynamic programming algorithm, it is difficult to analyze and answer.

However, I derived a method that works for all possible cases

Algorithm Sketch:

Iterate through the results of the target column in ascending order.

When the result increments, you have identified another subset and have found the largest value in that subset.

To find the remaining values in the subset, “make change” the way a store clerk would. In other words, walk back down the set values, subtracting from the remaining total as you can.

Sample Run:

For your given example of target sum = 12 for subsets within set [2,3,5,7,9]:

resultCount = 0

result(12,2) is 0; this result – resultCount = 0, so no new subsets

result(12,3) is 0; this result – resultCount = 0, so no new subsets

result(12,5) is 0; this result – resultCount = 0, so no new subsets

result(12,7) is 2; this result – resultCount = 1, so resultCount = 2

and new subset = [7]

and remaining = 12 – 7 = 5

5 = 5, so subset = [7,5] and remaining = 0 (subset complete)

result(12,7) is 2; this result – resultCount = 1, so resultCount = 2

and new subset = [7]

and remaining = 12 – 7 = 5

Again the algorithm is called internally for second time.

5=3+2, so subset=[7,3,2] and remaining = 0 (subset complete)

result(12,9) is 3; this result – resultCount = 1, so resultCount = 3

and new subset = [9]

and remaining = 12 – 9 = 3

7 > 3, so remaining is still 4

5 > 3, so remaining is still 4

3 = 3, so subset = [9,3] and remaining = 3 – 3 = 0(subset complete)

End of run with 3 subsets identified:

[7,5] , [7,3,2], [9,3]

Note: Based on your output table, there would be 3 subsets.

Grand Paper Writers
Order NOW For A 10% Discount!
Pages (550 words)
Approximate price: -

Our Advantages

Plagiarism Free Papers

All papers are written by the best professional writers to ensure 100% originality. We always provide plagiarism reports whenever we deliver completed papers.

Free Revisions

All papers by Grand Paper Writers are completed and submitted on time. This timely delivery of papers gives you time to go through the paper before the official deadline.

Title-page

As an additional service, we will provide a title page that precedes the contents of your paper. Here, you will provide your personal details.

Bibliography

We also ensure that we provide an extra page for the references or bibliographies following referencing rules.

Originality & Security

At Grandpaperwriters.com, we guarantee students for the provision of security and original work. All your personal information is handled with confidentiality and is not shared with third parties. Additionally, we ensure that we provide original content with accompanying plagiarism reports to show originality.

24/7 Customer Support

Our customer support team is always available 24/7 to provide instant responses to any queries raised by students.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Grandpaperwriters.com has the best professional essay writers for quality services.

Pricing

Flexible Pricing

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Communication

Admission Help & Client-Writer Contact

Grandpaperwriters.com provides an interactive portal where students can communicate directly to their writers.

Deadlines

Paper Submission

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Reviews

Customer Feedback

Grandpaperwriters.com appreciates feedback from our clients to help us improve the delivery of essay writing services. As such, we are constantly changing our policies to ensure maximum customer and writer satisfaction.