Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started