【PTA】【数据结构与算法】AVL树

判断题

1.Insert 1, 2, 3, 4, 5, and 6 one by one into an initially empty AVL tree. Then the preorder traversal sequence of the resulting tree must be {4, 2, 1, 3, 5, 6}. (2分)
T F

解析:以下演示了插入的过程,最后旋转得到的AVL树通过前序遍历可得到答案。在这里插入图片描述

2.For any node in an AVL tree, the height of the left subtree must be greater than that of the right subtree. (2分)
T F

解析:AVL树的定义是任一结点左右子树的差至多为1,所以可以左子树的高度比右子树高一,也可以右子树的高度比左子树高一。

3.For an AVL tree, the balance factors of all the non-leaf nodes are 0 if the tree is a complete binary tree. (2分)
T F

解析:完全二叉树不一定是满二叉树,可能有非叶子结点的左右子树高度不同。

4.If the depth of an AVL tree with nodes { 1, 2, 3, 4 } is 3 (the depth of the root is 1), then either node 2 or node 3 must have two children. (2分)
T F

解析:因为有4个结点,存在AVL树的调平机制,只可能存在一个根结点、左一结点和右二结点,或一个根结点、左二结点和右一结点,而因为二和三都是中间的结点,所以必有一个作为根节点且有两个孩子。

5.任何AVL树的中序遍历结果是有序的(从小到大)。 (2分)
T F

解析:AVL树是二叉搜索树,二叉搜索树的中序遍历是有序的(从小到大),故AVL树也满足。

6.For any node in an AVL tree, the height of the right subtree must be greater than that of the left subtree. (2分)
T F

解析:AVL树的定义是任一结点左右子树的差至多为1,所以可以左子树的高度比右子树高一,也可以右子树的高度比左子树高一。

7.An AVL tree with the balance factors of all the non-leaf nodes being 0 must be a perfect binary tree. (2分)
T F

解析:完美二叉树任一结点左右子树高度都是相等的且平衡因子都为0。

8.If the depth of an AVL tree with nodes { 1, 2, 3, 4 } is 3 (the depth of the root is 1), then it is possible for node 4 to be the root. (2分)
T F

解析:如果4作为根节点,其余三个结点都在4的左子树上,高度为2,而右子树高度为0,不平衡。

选择题

1.Which of the following is TRUE for any node in an AVL tree? (2分)
选项
A The left and right subtrees have the same height
B The absolute value of the difference between the heights of left and right subtrees is no more than 1
C The height of the left subtree is always greater than that of the right subtree
D The height of the left subtree is always less than that of the right subtree

解析:由定义得,任意结点左右子树的高度差的绝对值不大于1。

2.Insert key 48 into the balanced binary tree shown by the figure. Then in the resulting balanced tree, the left- and right-child of key 37 are: (2分)

在这里插入图片描述

选项
A 13 and 48
B 24 and 48
C 24 and 53
D 24 and 90

解析:

3.Insert 2, 1, 4, 5, 9, 3, 6, 7 into an initially empty AVL tree. Which one of the following statements is FALSE? (2分)
选项
A 4 is the root
B 3 and 7 are siblings
C 2 and 6 are siblings
D 9 is the parent of 7

解析:

4.If the depth of an AVL tree is 5 (the depth of an empty tree is defined to be −1), then the minimum possible number of nodes in this tree is: (2分)
选项
A 12
B 20
C 33
D 64

解析:由递推公式Nh = Nh-1 +Nh-2 +1得,深度为5的AVL数最少结点是20(空树深度为-1)。

5.Insert { 9, 8, 7, 2, 3, 5, 6, 4} into an initially empty AVL tree. Which one of the following statements is FALSE? (2分)
选项
A 5 is the root
B 2 and 5 are siblings
C there are 2 nodes with their balance factors being -1
D the height of the resulting AVL tree is 3

解析:

6.After inserting 28, 22, and 35 into the given AVL tree, the children of node 25 are __。 (2分)
选项
A 22 and 28
B 20 and 28
C 22 and 30
D 20 and 30

解析:

7.Among the following trees, which one satisfies the definition of a balanced tree? (2分)
选项
A —
B —
C —
D —

解析:由定义得,任意结点左右子树的高度差的绝对值不大于1。其余几个选项根结点就已经不满足定义了。

8.The maximum possible depth of an AVL tree with 12 nodes is: (2分)
选项
A 3
B 4
C 5
D 6

解析:由递推公式Nh = Nh-1 +Nh-2 +1得,深度为5的AVL数最少结点是12(空树深度为0)。

9.Insert {88, 70, 61, 96, 120, 90} one by one into an initially empty AVL tree. Then the preorder traversal sequence of the resulting AVL tree is: (2分)
选项
A 61,70,88,90,96,120
B 90,70,61,88,96,120
C 88,70,61,90,96,120
D 88,70,61,96,90,120

解析:

10.If the depth of an AVL tree is 6 (the depth of an empty tree is defined to be -1), then the minimum possible number of nodes in this tree is: (2分)
选项
A 13
B 17
C 20
D 33

解析:

11.如果AVL树的深度为5(空树的深度定义为−1),则此树最少有多少个结点?(2分)
选项
A 12
B 20
C 33
D 64

解析:由递推公式Nh = Nh-1 +Nh-2 +1得,深度为5的AVL数最少结点是20(空树深度为-1)。

12.将一系列数字顺序一个个插入一棵初始为空的AVL树。下面哪个系列的第一次旋转是“右-左”双旋?(2分)
选项
A 1,2,3,4,5,6
B 6,5,4,3,2,1
C 4,2,5,6,3,1
D 3,1,4,6,5,2

解析:

13.将 1, 2, 3, 6, 5, 4 顺序一个个插入一棵初始为空的AVL树,会经历下列哪些旋转? (2分)
选项
A 两个“右-右”旋和一个“右-左”旋
B 一个“右-右”旋、一个“右-左”旋、一个“左-右”旋
C 一个“右-右”旋和两个“右-左”旋
D 两个“右-右”旋和一个“左-右”旋

解析:

14.在任意一棵非空平衡二叉树(AVL 树)T​1​​中,删除某结点 v 之后形成平衡二叉树 T​2​​,再将 v 插入 T​​2​​形成平衡二叉树 T​​3。下列关于 T​1与 T​3​​的叙述中,正确的是:(2分)

 I、若 v 是 T​​1的叶结点,则 T​​1与 T​​3可能不相同
 II、若 v 不是 T​1​​的叶结点,则 T​1​​与 T​3​​一定不同
 III、若 v 不是 T​1​​的叶结点,则 T​1​​与 T​3​​一定相同

选项
A 仅 I
B 仅 II
C 仅 I、II
D 仅 I、III

解析:

15.首先将 28, 23, 54, 61, 98, 37 插入一棵初始为空的平衡二叉树(AVL树),然后马上插入下列选项中的一个键值。哪个键值将引起 RL 旋转?
选项
A 10
B 30
C 60
D 70

解析:

16.将 26, 13, 44, 51, 98, 37, 66, 73 顺序插入一棵初始为空的AVL树。下列句子中哪句是错的?
选项
A 44 是根结点
B 37 和 73 是兄弟
C 26 和 66 是兄弟
D 26 是 13 的父结点

解析:

发布了143 篇原创文章 · 获赞 140 · 访问量 27万+

猜你喜欢

转载自blog.csdn.net/qq_43733499/article/details/102981587