東京大学 新領域創成科学研究科 メディカル情報生命専攻 2015年8月実施 問題7
Author
Description
自然数 \(n (\geq 1)\) の大きさの入力データを処理するアルゴリズムの最悪計算時間を \(T(n)\)、実数 \(x\) 以下の最大の整数を \(\lfloor x \rfloor\) と記述する。 \(c \geq 1\) を定数とする。 \(T(n)\) が \(T(1)=c\) および \(n>1\) のとき以下の再帰的定義をみたす場合を各々考える。
- (1) \(T(n) = T(\lfloor 3n/4 \rfloor) + cn\)
- (2) \(T(n) = 2T(n - 1) + cn\)
- (3) \(T(n) = T(n - 1) + c(n^2 + n)\)
- (4) \(T(n) = T(\lfloor n/2 \rfloor) + c\)
- (5) \(T(n) = 2T(\lfloor n/2 \rfloor) + cn\)
各再帰的定義を満たす \(T(n)\) が属する最小のクラスを以下の計算量クラスから選び、その証明を示せ。
Let \(T(n)\) denote the worst-case running time of an algorithm that processes input data of size \(n (\geq 1)\). Let \(\lfloor x \rfloor\) be the largest integer that is equal to or smaller than real number \(x\). Let \(c (\geq 1)\) be a constant number. Suppose that \(T(n)\) meets \(T(1) = c\) and each of the following recurrences for \(n > 1\):
- (1) \(T(n) = T(\lfloor 3n/4 \rfloor) + cn\)
- (2) \(T(n) = 2T(n - 1) + cn\)
- (3) \(T(n) = T(n - 1) + c(n^2 + n)\)
- (4) \(T(n) = T(\lfloor n/2 \rfloor) + c\)
- (5) \(T(n) = 2T(\lfloor n/2 \rfloor) + cn\)
From the following complexity classes, select the smallest class for \(T(n)\) that satisfies each of the above recurrences, and prove the property:
Kai
(1)
For this recurrence, we use the Master Theorem. The recurrence is of the form \(T(n) = aT(n/b) + f(n)\).
- Here, \(a = 1\), \(b = \frac{4}{3}\), and \(f(n) = cn\).
- We need to compare \(f(n)\) with \(n^{\log_b a}\).
First, compute \(\log_b a\):
According to the Master Theorem:
- If \(f(n) = O(n^c)\) where \(c < \log_b a\), then \(T(n) = \Theta(n^{\log_b a})\).
- If \(f(n) = \Theta(n^{\log_b a})\), then \(T(n) = \Theta(n^{\log_b a} \log n)\).
- If \(f(n) = \Omega(n^c)\) where \(c > \log_b a\) and \(af(n/b) \leq kf(n)\) for some \(k < 1\) and sufficiently large \(n\), then \(T(n) = \Theta(f(n))\).
In this case, \(f(n) = cn = \Theta(n)\) and \(\log_b a = 0\).
Since \(c > \log_b a\), we have \(T(n) = \Theta(n)\).
Thus, \(T(n) \in O(n)\).
(2)
To solve this recurrence, we can use the iterative method:
When \(k = n - 1\):
The sum \(\sum_{i=1}^{n-2} 2^i\) is a geometric series:
Thus, \(T(n)\) can be approximated by:
Thus, \(T(n) \in O(3^n)\).
(3)
This is a non-homogeneous linear recurrence relation. We can use the iterative method:
The sum \(\sum_{k=1}^{n-1} k^2\) is:
And the sum \(\sum_{k=1}^{n-1} k\) is:
Therefore:
Thus, \(T(n) \in O(n^3)\).
(4)
For this recurrence, we again use the Master Theorem. The recurrence is of the form \(T(n) = aT(n/b) + f(n)\).
- Here, \(a = 1\), \(b = 2\), and \(f(n) = c\).
- We need to compare \(f(n)\) with \(n^{\log_b a}\).
First, compute \(\log_b a\):
According to the Master Theorem:
- If \(f(n) = O(n^c)\) where \(c < \log_b a\), then \(T(n) = \Theta(n^{\log_b a})\).
- If \(f(n) = \Theta(n^{\log_b a})\), then \(T(n) = \Theta(n^{\log_b a} \log n)\).
- If \(f(n) = \Omega(n^c)\) where \(c > \log_b a\) and \(af(n/b) \leq kf(n)\) for some \(k < 1\) and sufficiently large \(n\), then \(T(n) = \Theta(f(n))\).
In this case, \(f(n) = c = \Theta(1)\) and \(\log_b a = 0\).
Since \(f(n)\) is \(\Theta(n^0)\):
Thus, \(T(n) \in O(\log n)\).
(5)
For this recurrence, we use the Master Theorem. The recurrence is of the form \(T(n) = aT(n/b) + f(n)\).
- Here, \(a = 2\), \(b = 2\), and \(f(n) = cn\).
- We need to compare \(f(n)\) with \(n^{\log_b a}\).
First, compute \(\log_b a\):
According to the Master Theorem:
- If \(f(n) = O(n^c)\) where \(c < \log_b a\), then \(T(n) = \Theta(n^{\log_b a})\).
- If \(f(n) = \Theta(n^{\log_b a})\), then \(T(n) = \Theta(n^{\log_b a} \log n)\).
- If \(f(n) = \Omega(n^c)\) where \(c > \log_b a\) and \(af(n/b) \leq kf(n)\) for some \(k < 1\) and sufficiently large \(n\), then \(T(n) = \Theta(f(n))\).
In this case, \(f(n) = cn = \Theta(n)\) and \(\log_b a = 1\).
Since \(f(n) = \Theta(n^{\log_b a})\), we have:
Thus, \(T(n) \in O(n \log n)\).
Summary
- Recurrence 1: \(T(n) = \Theta(n)\), \(T(n) \in O(n)\).
- Recurrence 2: \(T(n) = \Theta(2^n)\), \(T(n) \in O(2^n)\).
- Recurrence 3: \(T(n) = \Theta(n^3)\), \(T(n) \in O(n^3)\).
- Recurrence 4: \(T(n) = \Theta(\log n)\), \(T(n) \in O(\log n)\).
- Recurrence 5: \(T(n) = \Theta(n \log n)\), \(T(n) \in O(n \log n)\).
Knowledge
主定理 递归 复杂度分析
解题技巧和信息
对于递归方程的时间复杂度分析,使用主定理是一个强大的工具。主定理适用于形如 \(T(n) = aT(n/b) + f(n)\) 的递归式。需要注意 \(a, b, f(n)\) 的取值以及 \(f(n)\) 和 \(n^{\log_b a}\) 的比较来判断最终的时间复杂度。对于不能用主定理的递归式,可以使用展开迭代法逐步分析。
重点词汇
- Recurrence Relation 递归关系
- Master Theorem 主定理
- Time Complexity 时间复杂度
- Logarithm 对数
- Big O Notation 大 O 符号
参考资料
- Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, 3rd Edition. MIT Press, Chapter 4.