[algogeeks] merging 2 search trees

2011-01-21 Thread snehal jain
You are given two height balanced binary search trees T and T’,
storing m and n elements respectively. Every element of tree T is
smaller than every element of tree T’. Every node u also stores height
of the subtree rooted at it. Using this extra information how can you
merge the two trees in time O(log m + log n) (preserving both the
height balance and the order)?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.



Re: [algogeeks] merging 2 search trees

2011-01-21 Thread nishaanth
Find the node in T which is the maximum(which is either the root or the
rightmost in the right subtree).
After finding this node, just make the right child of this node point to the
root of T'.

Correct me if i am wrong

On Fri, Jan 21, 2011 at 2:43 PM, snehal jain learner@gmail.com wrote:

 You are given two height balanced binary search trees T and T’,
 storing m and n elements respectively. Every element of tree T is
 smaller than every element of tree T’. Every node u also stores height
 of the subtree rooted at it. Using this extra information how can you
 merge the two trees in time O(log m + log n) (preserving both the
 height balance and the order)?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
S.Nishaanth,
Computer Science and engineering,
IIT Madras.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@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.



Re: [algogeeks] merging 2 search trees

2011-01-21 Thread Divya Jain
@ above height will not be balanced then

On 21 January 2011 19:15, nishaanth nishaant...@gmail.com wrote:

 Find the node in T which is the maximum(which is either the root or the
 rightmost in the right subtree).
 After finding this node, just make the right child of this node point to
 the root of T'.

 Correct me if i am wrong


 On Fri, Jan 21, 2011 at 2:43 PM, snehal jain learner@gmail.comwrote:

 You are given two height balanced binary search trees T and T’,
 storing m and n elements respectively. Every element of tree T is
 smaller than every element of tree T’. Every node u also stores height
 of the subtree rooted at it. Using this extra information how can you
 merge the two trees in time O(log m + log n) (preserving both the
 height balance and the order)?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 S.Nishaanth,
 Computer Science and engineering,
 IIT Madras.

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%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 algogeeks@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.