Algorithm 合并二叉搜索树

Algorithm 合并二叉搜索树,algorithm,merge,binary-search-tree,Algorithm,Merge,Binary Search Tree,我正在寻找一种合并两个BST的有效方法,因为我知道第一个树中的元素都比第二个树中的元素低。 我看到了一些合并方法,但没有这个功能,我认为这应该简化算法 有什么想法吗?如果树不平衡,或者结果不应该平衡,这很容易: without loss of generality - let the first BST be smaller (in size) than the second. 1. Find the highest element in the first BST - this is done

我正在寻找一种合并两个BST的有效方法,因为我知道第一个树中的元素都比第二个树中的元素低。 我看到了一些合并方法,但没有这个功能,我认为这应该简化算法


有什么想法吗?

如果树不平衡,或者结果不应该平衡,这很容易:

without loss of generality - let the first BST be smaller (in size) than the second.
1. Find the highest element in the first BST - this is done by following the right son while it is still available. Let the value be x, and the node be v
2. Remove this item (v) from the first tree
3. Create a new Root with value x, let this new root be r
4. set r.left = tree1.root, r.right = tree2.root
(*)如果第一个BST的大小大于第二个BST,只需重复查找
v
作为第二棵树中最小节点的过程


(*)复杂性是
O(min{T1},T2})
最坏情况(如果树非常不平衡,则查找最高元素)和
O(log(min{T1},T2})
平均情况-如果树相对平衡。

树是平衡的吗?它们假设保持这种方式吗?树不是平衡的,但不应该是丝状的?什么是“丝状的”?你的意思是你不想/不允许简单地将一棵树放到另一棵树上?你需要做一些平衡来将它们完全合并在一起,这就是你的意思吗?对不起,我是法国人,我的意思是我不想有一个每个节点只有一个子的树。像一棵细长的(?)树