東京大学 情報理工学系研究科 コンピュータ科学専攻 2016年2月実施 問題3
Author
kainoj, 祭音Myyura
Description
Answer the following questions concerning binary search trees. Here, the height of a node is defined as the maximum of the graph distance from the node to one of its descendant leaf nodes. For example, a node with no children is of height 0. The height of a tree is defined as the height of its root.
(1) Suppose that we have the following binary search tree.
9
/ \
4 12
/ \ / \
2 7 10 14
/
6
Let us apply the following operations to the above tree, in the shown order.
- (i) Insert 3
- (ii) Insert 8
- (iii) Delete 4
- (iv) Delete 9
Depict the state of the tree after each operation.
(2) Answer the minimum and maximum tree heights of a binary search tree with nodes.
We call a binary search tree balanced if every node of it satisfies the following conditions:
- In case the node has two children, the heights of the left and right child subtrees differ by at most .
- In case the node has only one child, the height of the child subtree is .
Answer the following questions.
(3) Answer the minimum and maximum tree heights of a balanced binary search tree with nodes. Depict a tree with the maximum height, and one with the minimum height.
(4) Answer the minimum tree height of a balanced binary search tree with nodes.
(5) Show that the height of a balanced binary search tree with nodes is no more than .
题目描述
回答关于二叉搜索树的下列问题。结点的“高度”定义为该结点到其后代叶结点的最大图距离;例如,无子结点的结点高度为 。树的高度定义为根结点的高度。
(1)对题图所示的二叉搜索树,按顺序执行:
- 插入 ;
- 插入 ;
- 删除 ;
- 删除 。
画出每次操作后的树。
(2)给出含 个结点的二叉搜索树可能具有的最小高度和最大高度。
若二叉搜索树的每个结点均满足以下条件,则称其为平衡二叉搜索树:
- 有两个子结点时,左右子树的高度差不超过 ;
- 只有一个子结点时,该子树的高度为 。
继续回答:
(3)给出含 个结点的平衡二叉搜索树的最小高度和最大高度,并分别画出达到最大高度和最小高度的树。
(4)给出含 个结点的平衡二叉搜索树的最小高度。
(5)证明含 个结点的平衡二叉搜索树的高度不超过 。
Kai
(1)
(i)
9
/ \
4 12
/ \ / \
2 7 10 14
\ /
3 6
(ii)
9
/ \
4 12
/ \ / \
2 7 10 14
\ / \
3 6 8
(iii)
9
/ \
3 12
/ \ / \
2 7 10 14
/ \
6 8
(iv)
8
/ \
3 12
/ \ / \
2 7 10 14
/
6
(2)
Minimum height of BST with nodes is . Maximum height: .
(3)
AVL tree with nodes has min. height of (full binary tree), and max. height of . See following:
3
/ \
2 1
/ \ /
1 0 0
/
0
(4)
Just – it's a full binary tree.
(5)
Show that the height of a balanced binary tree (AVL) with nodes is no more than .
Let's consider the smallest possible AVL trees wrt number of nodes. Let indicate minimum number of nodes in a balanced tree of height . The minimum tree of nodes and height consists of a root, a minimum subtree of of height and a minimum subtree of height :
Taking log both sides: .