1.Add 0 to the array if the number of elements in the given array is odd. 2.Count the frequency of each element or we can simply sort it. 3.If the frequency is even for any element then that element can be distributed among two parts equally(say p1 and p2). 4.For the elements having odd frequency(f) NOT=1, we can still distribute them by (f-1)/2 each into p1 and p2 leaving with only one instance of each odd frequency elements.(say in set S) 5.Now we are left with to divide the elements of the set S into p1 and p2(equal number of elements in each part) such that the difference of sum of p1 and p2 is minimum. 6.say the sum of the elements of the set S is X and the number of elements is N. So,we need to check if we can have N/2 elements in S such that their sum equals to X/2(if X is even;else (X-1)/2). And if it is not equal then try for the closest value. 7.If we are able to find such a combination then the difference will be 0(if X is even) or 1(if it is odd). if not then the minimum difference will be X-(2*sum of the N/2 elements(as close as possible to X/2)).
thanks, Anitesh. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.