Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a set of n integers with total sum W, write an O(nW) time algorithm to divide it into two sets S1 and S2 such

Given a set of n integers with total sum W, write an O(nW) time algorithm to divide it into two sets S1 and S2 such that the absolute difference between their sums is minimum. You just need to output the absolute difference, not the two sets. If we assume S1 has m elements, S2 must have n m elements, and the value of | P aS1 a P bS2 b| should be minimum. Note that the value of |x y| is x y if x y, otherwise it is y x. Example: Input: {1, 6, 11, 5} Output: 1 Explanation: S1 = {11}, sum of the numbers in S1 = 11 S2 = {1, 5, 6}, sum of the numbers in S2 = 12. The absolute difference is 1.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions

Question

Prepare a constructive performance appraisal.

Answered: 1 week ago

Question

List the advantages of correct report formatting.

Answered: 1 week ago