@Expert,
u r right, it will take nlogn time.
But I didn't get this part of the code:
else {
  if ( && map[num] == false){
     map[ S - num ] = true ;
  } else {

}

can u please provide us a little explanation?


On Sat, Jun 12, 2010 at 2:34 PM, Modeling Expert <
cs.modelingexp...@gmail.com> wrote:

> As problem says N is very large, I think sorting is not the right
> thing as that would be minimum (n log n) time
> how about this
> Let's say sum is S
> we take an map<int,boo> map and start reading integerts num
> if ( num > S ) discard
> else {
>   if ( && map[num] == false){
>      map[ S - num ] = true ;
>   } else {
>
> }
>
>
> On Jun 12, 11:40 am, Chakravarthi Muppalla <chakri...@gmail.com>
> wrote:
> > 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>
> <algogeeks%2bunsubscr...@googlegroups.com<algogeeks%252bunsubscr...@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>
> <algogeeks%2bunsubscr...@googlegroups.com<algogeeks%252bunsubscr...@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<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