京都大学 情報学研究科 知能情報学専攻 2021年2月実施 基礎科目 F2-1
Author
祭音Myyura (co-authored with GPT 5.6 SOL)
Description
Answer the following questions about binary search trees.
(1) Draw one binary search tree of smallest height containing the nine elements
(2) Draw one binary search tree of greatest height containing the same elements.
(3) Suppose each element is queried with equal probability in the tree given in (1). What is the expected number of visited nodes required to find it?
(4) A binary search tree is a complete binary tree with distinct elements, where is a positive integer. If each element is queried with equal probability, what is the expected number of visited nodes required to find it?
题目描述
回答有关二叉搜索树的问题。
- 用元素 画一棵高度最小的二叉搜索树。
- 用同一组元素画一棵高度最大的二叉搜索树。
- 在第 1 问所画的树中等概率查询一个元素,求成功找到该元素所访问结点数的期望。
- 一棵二叉搜索树是含 个互异元素的完全二叉树。等概率查询一个元素时, 求成功查找所访问结点数的期望。
Kai
(1)
One smallest-height tree is
10
/ \
6 14
/ \ / \
1 8 13 17
/ /
7 11
Its height is when height is counted by edges, or equivalently it has four levels. No tree of height can contain nine nodes because it can contain at most nodes.
(2)
A degenerate binary search tree has the greatest possible height:
1
\
6
\
7
\
8
\
10
\
11
\
13
\
14
\
17
Its height is edges, or nine levels.
(3)
In the tree from (1), the numbers of nodes at depths are , respectively. A node at depth requires visits. Therefore,
(4)
The tree has levels. Level contains nodes, and finding a node on that level requires visits. Thus
Hence