東京大学 新領域創成科学研究科 メディカル情報生命専攻 2017年8月実施 問題7
Author
zephyr
Description
Let n be a positive integer. Let f(n) and g(n) denote functions that represent computation time for solving a problem of size n. To provide asymptotic upper and lower bounds on f(n), we define the following sets of functions, O(g(n)) and Ω(g(n)), respectively:
O(g(n))={f(n)∣There exist positive constants c0 and n0 such that 0≤f(n)≤c0g(n) for all n≥n0}
Ω(g(n))={f(n)∣There exist positive constants c0 and n0 such that 0≤c0g(n)≤f(n) for all n≥n0}
Answer the following questions.
(1) Let f(n)=22n. Prove whether f(n) is in O(2n), and whether f(n) is in Ω(2n).
(2) Let f(n)=∑i=1n(1/i). Prove whether f(n) is in O(logn), and whether f(n) is in Ω(logn).
(3) Let ⌊x⌋ be the largest integer that is equal to or smaller than real number x. Suppose that f(n) satisfies that f(1)=1 and f(n)=f(⌊n/2⌋)+n for n≥2. Prove whether f(n) is in O(n), and whether f(n) is in Ω(n2).
设 n 为正整数。令 f(n) 和 g(n) 表示解决大小为 n 的问题的计算时间函数。为了提供 f(n) 的渐近上界和下界,我们分别定义了以下函数集 O(g(n)) 和 Ω(g(n)):
O(g(n))={f(n)∣存在正常数 c0 和 n0 使得 0≤f(n)≤c0g(n) 对于所有 n≥n0}
Ω(g(n))={f(n)∣存在正常数 c0 和 n0 使得 0≤c0g(n)≤f(n) 对于所有 n≥n0}
回答下列问题。
(1) 令 f(n)=22n。证明 f(n) 是否在 O(2n) 中,以及 f(n) 是否在 Ω(2n) 中。
(2) 令 f(n)=∑i=1n(1/i)。证明 f(n) 是否在 O(logn) 中,以及 f(n) 是否在 Ω(logn) 中。
(3) 设 ⌊x⌋ 为等于或小于实数 x 的最大整数。假设 f(n) 满足 f(1)=1 且 f(n)=f(⌊n/2⌋)+n 对于 n≥2。证明 f(n) 是否在 O(n) 中,以及 f(n) 是否在 Ω(n2) 中。
Kai
(1)
Part (a): Prove whether f(n) is in O(2n)
To prove f(n)∈O(2n), we need to find constants c0 and n0 such that:
0≤22n≤c0⋅2n for all n≥n0.
Notice that 22n=(2n)2. This grows much faster than 2n. To find such c0 and n0:
22n≤c0⋅2n⇒2n≤c0.
For this to hold for all n≥n0, c0 would have to be infinite, which is not possible. Therefore,
f(n)=22n∈/O(2n).
Part (b): Prove whether f(n) is in Ω(2n)
To prove f(n)∈Ω(2n), we need to find constants c0 and n0 such that:
0≤c0⋅2n≤22n for all n≥n0.
Notice that:
c0⋅2n≤22n⇒c0≤2n.
For large n, 2n grows exponentially, so we can choose any positive constant c0 and it will be less than 2n for sufficiently large n. Thus, we can choose n0=1 and any c0>0:
f(n)=22n∈Ω(2n).
(2)
Part (a): Prove whether f(n) is in O(logn)
To prove f(n)∈O(logn), we need to find constants c0 and n0 such that:
0≤i=1∑ni1≤c0logn for all n≥n0.
Let's use the properties of the harmonic series. We know that:
i=1∑ni1≤1+∫1nx1dx.
Evaluating the integral, we get:
∫1nx1dx=logn.
Thus,
i=1∑ni1≤1+logn.
For sufficiently large n, the term 1+logn can be bounded by c0logn for some constant c0≥1. Hence,
f(n)=i=1∑ni1∈O(logn).
Part (b): Prove whether f(n) is in Ω(logn)
To prove f(n)∈Ω(logn), we need to find constants c0 and n0 such that:
0≤c0logn≤i=1∑ni1 for all n≥n0.
We can compare the harmonic series with the integral from below. Specifically,
i=1∑ni1≥∫1n+1x1dx.
Evaluating the integral, we get:
∫1n+1x1dx=log(n+1).
Thus,
i=1∑ni1≥log(n+1).
For sufficiently large n, log(n+1) can be bounded from below by c0logn for some constant c0>0. Thus, we can choose c0=1 and n0=1:
f(n)=i=1∑ni1∈Ω(logn).
(3)
Part (a): Prove whether f(n) is in O(n)
To analyze this, we use the Master Theorem for divide-and-conquer recurrences. Here, the recurrence is:
f(n)=f(⌊n/2⌋)+n.
This fits the form f(n)=af(n/b)+g(n) with a=1, b=2, and g(n)=n. The Master Theorem states:
- If g(n)=O(nc) where c<logba, then f(n)=Θ(nlogba).
- If g(n)=Θ(nlogba), then f(n)=Θ(nlogbalogn).
- If g(n)=Ω(nc) where c>logba, and if ag(n/b)≤kg(n) for some k<1 and sufficiently large n, then f(n)=Θ(g(n)).
In this case, logba=log21=0, and g(n)=n. Since n=Ω(n0) and g(n)=n, case 3 of the Master Theorem applies, giving us:
f(n)=Θ(n).
Thus,
f(n)∈O(n).
Part (b): Prove whether f(n) is in Ω(n2)
We already have from the Master Theorem that f(n)=Θ(n). Therefore, f(n) is not Ω(n2), because Θ(n) implies both upper and lower bounds O(n) and Ω(n).
Thus,
f(n)∈/Ω(n2).
Knowledge
递归 主定理 复杂度分析
重点词汇
- Asymptotic bounds 渐近界
- Master Theorem 主定理
- Harmonic series 调和级数
- Exponential function 指数函数
- Recurrence 递归
参考资料
- Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, 3rd Edition. MIT Press. Chapter 3: Growth of Functions, and Chapter 4: Divide-and-Conquer.
- Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser. Data Structures and Algorithms in Java, 6th Edition. Wiley. Chapter 5: Recursion.