東京大学 情報理工学系研究科 コンピュータ科学専攻 2017年8月実施 専門科目II 問題3
Author
Description
Let
Here, we have a binary tree
is a leaf. has only one child, and the height of is . has two children, and the heights of the two children of differ by .
Let
Answer the following questions:
(1) Calculate
(2) Express
(3) Prove that
(4) Prove that
(5) Consider the problem of assigning each of the given
Kai
Setting:
(1)
(2)
Bonus: note that
Proof goes by induction:
Inductive step:
(3)
Note that
and multiply it by
The rest goes by induction.
Base case:
Inductive step:
(4)
Again, by induction.
Base: tree of height
Induction:
(5)
We are tasked with constructing an AVL tree of height
Algorithm Steps:
Precompute Subtree Sizes: Use dynamic programming to calculate the sizes of all subtrees up to height
This step runs in
Main Function fillTree(arr, h)
:
- Base case: if
, return a tree with a single node containing the first element of arr
. - Calculate the sizes for left and right subtrees using the precomputed
:
- Use
quickSelect
to find the(leftSize+1)th
smallest element inarr
to be the root. - Recursively fill the left subtree with the smallest
leftSize
elements, and the right subtree with the largestrightSize
elements. - Return the tree.
QuickSelect: This algorithm finds the kth smallest element in an array in average
To rigorously analyze the time complexity of constructing the AVL tree, we use the Akra-Bazzi Theorem, which is a generalization of the Master Theorem and is more suitable for handling recurrences with multiple recursive branches and non-uniform problem sizes.
The time complexity
Determine
Hence we have