Given is a set of elements. You have to divide them into groups of two, such that the difference between the sum of elements of an individual group is minimum.
example:
5
4 6 7 2 1
two groups are: {4,6}
and {7,2,1}
.
My approach: I have come across only the brute force solution of this problem, i.e. generate all the subsets (2^n)
of the set using bit shifting technique.
I am looking for a better solution.