How to merge two BST's efficiently?
问题 How to merge two binary search trees maintaining the property of BST? If we decide to take each element from a tree and insert it into the other, the complexity of this method would be O(n1 * log(n2)) , where n1 is the number of nodes of the tree (say T1 ), which we have splitted, and n2 is the number of nodes of the other tree (say T2 ). After this operation only one BST has n1 + n2 nodes. My question is: can we do any better than O(n1 * log(n2))? 回答1: Naaff's answer with a little more