I would use an array.

a[] = 1 3 7 8 9 78 67 23
a[] = 1 3 7 8 9 23 67 78 //sort the array
reqSum = 30;
for i :a.length-1; i>=0; i--
     t = reqSum - a[i];
     if(t is negative) continue;
      find(t);//in the rest of the array;(binary search)
      if(t found in the array) return index of t, current value of i;
 I guess it works.(we may have to use a hash map to speed it up in the long
run).




On Sat, Jun 12, 2010 at 10:29 AM, Rohit Saraf
<rohit.kumar.sa...@gmail.com>wrote:

> I guess it can be done in efficiently using a simple divide and conquer
> scheme almost imitating mergesort.
> Can you think of it now? :D
>
> --------------------------------------------------
> Rohit Saraf
> Second Year Undergraduate,
> Dept. of Computer Science and Engineering
> IIT Bombay
> http://www.cse.iitb.ac.in/~rohitfeb14
>
>
>
> On Fri, Jun 11, 2010 at 10:07 PM, sharad kumar 
> <sharad20073...@gmail.com>wrote:
>
>> all possible pairs
>>
>> --
>> 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.
>>
>
>  --
> 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.
>



-- 
Thanks,
Chakravarthi.

-- 
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.

Reply via email to