由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - What's the efficient way to merge two BST?
相关主题
google inerview question (转载)[合集] 微软的一个面试题
随机数与概率Convert a binary tree to a BST... in place..
请教大家一个问题 (转载)请教算法题
问一个NN训练模型输入问题请教算法题
some interview questions问个c++的template的问题
阅读Robert Sedgewick的"algorithms in C"的感受这个Binary Tree的题来看看
请教双键的动态结构用什么数据结构比较好?请问合并两个BST的算法
binary search tree和hash table,各在什么场合用的多啊?有什么方法可以优化hashtable?
相关话题的讨论汇总
话题: bst话题: root话题: node话题: what话题: efficient
进入Programming版参与讨论
1 (共1页)
j*****k
发帖数: 1198
1
Eg: BST1 B1, BST2 B2.
Choose the root which has bigger value to be the new BST's root,
then insert each node of the other BST into the new BST. If B1
has m nodes, B2 has n modes, it takes O(mn). That's not good. Is
there other more efficient way?
e***r
发帖数: 68
2
According to :
Joining of two BSTs at Page552:
Program 12.23 Joining of two BSTs
If either BST is empty, the other is the result. Otherwise, we combine the
two BSTs by (arbitrarily) choosing the root of the first as the root, root
inserting that root into the second, then (recursively) combining the pair
of left subtrees and the pair of right subtrees.
private Node joinR(Node a, Node b)
{ if (b == null) return a;
if (a == null) return b;
insertT(b, a.item); //把a插入到b
1 (共1页)
进入Programming版参与讨论
相关主题
有什么方法可以优化hashtable?some interview questions
Re: 别了,纽约 (转载)阅读Robert Sedgewick的"algorithms in C"的感受
convert sorted array to binary search tree, 非递归怎么解?请教双键的动态结构用什么数据结构比较好?
一般操作很多的数据用什么数据结构?binary search tree和hash table,各在什么场合用的多啊?
google inerview question (转载)[合集] 微软的一个面试题
随机数与概率Convert a binary tree to a BST... in place..
请教大家一个问题 (转载)请教算法题
问一个NN训练模型输入问题请教算法题
相关话题的讨论汇总
话题: bst话题: root话题: node话题: what话题: efficient