@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 <
[email protected]> 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 <[email protected]>
> 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
> > <[email protected]>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 <
> [email protected]>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 [email protected].
> > >> To unsubscribe from this group, send email to
> > >> [email protected]<algogeeks%[email protected]>
> <algogeeks%[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]>
> <algogeeks%[email protected]<algogeeks%[email protected]>
> >
> > > .
> > > 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 [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.
>
>
--
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 [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.