On 2010-1-28 21:03, Nirmal wrote:
Given two binary search trees, how to merge them in O(n) time and O(1)
space?
It can be done using O(n) space as below,
1. covert BST #1 into linked list or sorted array
2. covert BST #2 into linked list or sorted array
3. merge them...
but how to do this in place?
--
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.
1) and 2) is not necessary.
Inorder traversal both BST simultaneously,
and merge the visited nodes into new BST,
just like ordinary sorted array merge.
--
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.