(1)从空树开始构造平衡二叉搜索树,画出每加入一个新结点时二叉树的形态。若发生不平衡,指明需进行的平衡旋转的类型及平衡旋转的结果
(2)计算该平衡二叉搜索树在等概率下的搜索成功的平均搜索长度和搜索不成功的平均搜索长度。
(1)从空树开始构造平衡二叉搜索树,画出每加入一个新结点时二叉树的形态。若发生不平衡,指明需进行的平衡旋转的类型及平衡旋转的结果
(2)计算该平衡二叉搜索树在等概率下的搜索成功的平均搜索长度和搜索不成功的平均搜索长度。
从空二叉树开始,严格按照二叉搜索树的插入算法(不进行旋转平衡),逐个插入关键码构造出一棵二叉树,以怎样的顺序插入关键码集合{14,32,47,6,9,12,78,63,29,81}可以使得树的深度最小? 请依次写出插入到树中的元素,每两个元素之间用一个空格隔开。 如果有多组满足要求的方案,请使得你的答案中先插入的元素尽可能的小。 From a null binary tree, insert key values successively according to the insertion algorithm of a binary search tree strictly (no rotation and balance) to construct a binary search tree. What is the insertion sequence that could make the tree have a smallest depth with a key value set {14,32,47,6,9,12,78,63,29,81}? Please write down the elements successively, and there is one blank space between two elements. If there are more than one answer that meet the condition, please make the element which needs to be inserted first as small as possible in your answer.
解题思路:二叉树的先序遍历非递归算法利用栈结构,从二又树的根结点开始,输出结点信息,同时将结点指针入栈,然后顺着左子树,依次将其左子树各个结点值输出,同时结点指针入栈,直到左子树为空;然后让栈顶指针出栈,接着处理右子树。
A、2, 10, 15, 28, 32, 65
B、32, 2, 10, 15, 28, 65
C、10, 28, 15, 2, 65, 32
D、32, 2, 15, 10, 28, 65
从空二叉树开始,严格按照二叉搜索树的插入算法(不进行旋转平衡),逐个插入关键码构造出一棵二叉树,以怎样的顺序插入关键码集合{14,32,47,6,9,12,78,63,29,81}可以使得树的深度最小? 请依次写出插入到树中的元素,每两个元素之间用一个空格隔开。 如果有多组满足要求的方案,请使得你的答案中先插入的元素尽可能的小。 From a null binary tree, insert key values successively according to the insertion algorithm of a binary search tree strictly (no rotation and balance) to construct a binary search tree. What is the insertion sequence that could make the tree have a smallest depth with a key value set {14,32,47,6,9,12,78,63,29,81}? Please write down the elements successively, and there is one blank space between two elements. If there are more than one answer that meet the condition, please make the element which needs to be inserted first as small as possible in your answer.
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!