Well if you want a sum of exactly 0 (or any constant) , there is an O(N^2) way
Take your array, and hash it, note that it is always possible to hash a static set of keys so that the search/find in it is worst case O(1). This takes O(N) space, and time. Then over all the tuples of numbers in the original array (a,b) check if 0 - (a+b) is there in the hash set, time complexity O(N*N). For closest to 0 I guess the above solution is good. On Mon, May 3, 2010 at 2:18 PM, jalaj jaiswal <jalaj.jaiswa...@gmail.com>wrote: > > given an array(unsorted) may contain negative numbers too > find the index of three numbers whose sum is closest to zero in O(N2 log > N) time and O(N) space. > > P.S -3 is more close to zero then -6 (number line ...) > -- > With Regards, > Jalaj Jaiswal > +919026283397 > B.TECH IT > IIIT ALLAHABAD > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- We are here on earth to do good for others. What the others are here for, I don't know. Afroz Mohiuddin Final Year Masters Student Dept Computer Science and Engineering Indian Institute of Technology Kanpur Kanpur - 208016 INDIA -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@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.