0

during my exam preparation, i have found this question which i am unable to solve nor find a solution on the web. I have been struggling for a couple of hours trying to figure this one out with no luck.

the problem goes as follows: given a black box that returns true if there exists 2 subsets T and S/T of a set S with equal sum and false if there isn't, in polynomial time.

suppose you are given a set S and the above black box find a subset T where the sum of T and the sum of (S/T) are equal.

thanks in advance.

Shak
  • 418
  • 1
  • 4
  • 14
  • To clarify - does the black box solve the problem "is there a partition of S into two sets X and Y with equal sum," or "are there two different subsets of S, possibly overlapping and possibly not containing all elements of S, that have the same sum?" – templatetypedef Aug 04 '16 at 18:49
  • the first option is the correct one. i will edit for clarity. – Shak Aug 04 '16 at 19:47

1 Answers1

1

For each pair of numbers A and B in the set, you can do a test to see if they are both in the same partition in one of the valid partitions: remove A and B from the set and replace with C, the sum of A + B. If the black box returns true for the new set then A and B must be part of the same partition. If so, leave C in the set. If not, put A and B back in and try another pair.

Repeat until there are only 2 numbers left in the set, keeping track of which numbers you added together to produce them. This gives you the two partitions.

samgak
  • 23,944
  • 4
  • 60
  • 82