We do not compare to a value. We compare each pair to current min and if the absolute sum of the current pair is less than the current min, we make the current pair sum the current min.
Do checkout this link: http://geeksforgeeks.org/?p=4034 Thanks, Balaji. On Tue, Jan 25, 2011 at 9:35 AM, siddharth srivastava <[email protected]>wrote: > Hi > > On 24 January 2011 12:55, Balaji Ramani <[email protected]> wrote: > >> @Siddharth >> >> However if the input range is unknown, it can be solved through an >> entirely different approach after sorting and then using two pointers moving >> either side from the positive-negative boundary. O(nlogn) + O(n) = O(nlogn) >> > > yes I meant this case only. But to what value would you compare if you want > the sum to be closest to zero and lets say that none of the elements sum up > to zero. > >> >> Thanks, >> Balaji. >> >> >> On Mon, Jan 24, 2011 at 11:03 PM, siddharth srivastava < >> [email protected]> wrote: >> >>> If the same question is modified as: >>> Find two numbers whose sum is closest to zero in the given array. >>> >>> >>> On 24 January 2011 16:08, juver++ <[email protected]> wrote: >>> >>>> Its name is meet-in-the-middle technique. >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]<algogeeks%[email protected]> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>> >>> >>> >>> -- >>> Siddharth Srivastava >>> >>> When you have learned to snatch the error code from the trap frame, it >>> will be time for you to leave. >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]<algogeeks%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<algogeeks%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Siddharth Srivastava > > When you have learned to snatch the error code from the trap frame, it will > be time for you to leave. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
