Divide set of values into two sets of same or similar size with similar value sums

柔情痞子 提交于 2019-12-02 12:30:50

My suggestion would be to sort the values, then consider each pair of values (v1, v2), (v3, v4) putting one element from each pair into one partition.

The idea is to alternate putting the values into each set, so:

s1 = {v1, v4, v5, v8, . . . }
s2 = {v2, v3, v6, v7, . . . }

If there are an odd number of elements, put the last value into the set that best meets your conditions.

You have a relaxed definition of minimal, so a full search is unnecessary. The above should work quite well for many distributions of the values.

It easy to prove that the partition problem reduces to this problem in polynomial time.

Imagine you want to solve partition for some array A, but you only know how to solve your problem. You just have to double the array length, filling it with zeros. If you can solve it with your algorithm, then you have solved the partition problem. This proves your problem to be NP-hard.

But you'll see you can't reduce this problem to partition (i.e. it isn't NP-complete), unless you limit the precision of your floats. In that case the same algorithm would solve both.

In the general case, the best you can do is backtrack.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!