with order of n space , we can easily do.. just copy inorder traversal in
array.. keep two pointers one at beg and 1 at end.... increment and
decrement accordingly until two pointers meet...
but how to do in constant space and O(n) ??

On Fri, May 14, 2010 at 11:17 PM, W Karas <wka...@yahoo.com> wrote:

> If you need an array large enough to hold all tree elements, that is
> not constant space, it is O(n) space.
>
> On May 14, 5:47 am, divya jain <sweetdivya....@gmail.com> wrote:
> > form a sorted  array from inorder traversal of tree. now take to pointers
> > one to the beginning of array and other at the end. now check if the sum
> of
> > element is greater than reqd sum then increment 1st ptr. if their sum is
> > less than reqd sum then decrement 2nd ptr. if their sum is equal to the
> reqd
> > sum then this is the ans..
> > hope it will work..
> >
> > On 13 May 2010 20:11, jalaj jaiswal <jalaj.jaiswa...@gmail.com> wrote:
> >
> >
> >
> > > given a bst... find two nodes whose sum is equal to a number k ... in
> O(n)
> > > time and constant space...
> >
> > > --
> > > 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>
> <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>
> .
> > For more options, visit this group athttp://
> 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.
>
>


-- 
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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to