Hi,

@Asish meena  and Arun :
       I dont think you can simply append a whole tree( BST2) at some
position just because the root of the BST2 is at its correct position.For
instance ,  Lets say you append BST2's Root anywhere within the left subtree
of BST1's Root. But if the right most leaf node of BST2 is greater than the
root of BST1, then the merged tree is no longer a binary search tree. Hence
your approach will not work in all cases.


On Wed, Feb 10, 2010 at 5:12 PM, r_arun <[email protected]> wrote:

> Your algorithm is correct. But
>
> > 3. Remove the children from this place and store them as BST3 and BST4.
>
> This is not required , because trying to merge BST2 with BST1,which is
> equivalent to finding a place to insert a pointer to root of BST2 in
> BST1. Whenever you need a place for a new node, you take a place of a
> existing leaf in BST1 for that new node. So we need not worry about
> children.
>
> Also in a BST there is no configuration for which a new element can
> not be inserted.
>
> So we can just link the pointers and get a merged tree.
>
> --
> 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.

Reply via email to