0

Usually what we do is 1.we calculate sum of whole array from left and call it Leftsum 2.then we starts traversing array from Right end and start adding every element into RIGHTSUM, and subracting every element from LEFTSUM 3. untill LEFTSUM=RIGHTSUM,then we assign current value of iterator variable I to splitpoint 4.Now array before SPLITPOINT index and from SPLITPOINT index to end have equal sum

MAIN PROBLEM------>

but this will work if array is ((3 , 5 , 10) , (3, 10 , 5)) but not on (3 , 5 , 5 , 3, 10 , 10) because we cannot find SPLITPOINT here whose left and right array sum is equal

answer of second part should also be (3,5,10) (5,3,10) Again sum of 2 parts should be equal not length this is an easy illustation example above

1 Answers1

1

Suppose the total for the whole sequence is N. You're effectively looking for a sub-sequence that sums to N/2. (Note: if N is odd, there is no such sub-sequence!)

This is the "subset sum" problem. There's a decent Java solution for that at Finding all possible combinations of numbers to reach a given sum.

Joe Halliwell
  • 1,155
  • 6
  • 21