跳到主要内容

東京大学 新領域創成科学研究科 メディカル情報生命専攻 2017年8月実施 問題7

Author​

zephyr, 祭音Myyura

Description​

Let nn be a positive integer. Let f(n)f(n) and g(n)g(n) denote functions that represent computation time for solving a problem of size nn. To provide asymptotic upper and lower bounds on f(n)f(n), we define the following sets of functions, O(g(n))O(g(n)) and Ω(g(n))\Omega(g(n)), respectively:

O(g(n))={f(n)∣There exist positive constants c0 and n0 such that 0≤f(n)≤c0 g(n) for all n≥n0}O(g(n)) = \{f(n) \mid \text{There exist positive constants } c_0 \text{ and } n_0 \text{ such that } 0 \leq f(n) \leq c_0 \, g(n) \text{ for all } n \geq n_0\}
Ω(g(n))={f(n)∣There exist positive constants c0 and n0 such that 0≤c0 g(n)≤f(n) for all n≥n0}\Omega(g(n)) = \{f(n) \mid \text{There exist positive constants } c_0 \text{ and } n_0 \text{ such that } 0 \leq c_0 \, g(n) \leq f(n) \text{ for all } n \geq n_0\}

Answer the following questions.

(1) Let f(n)=22nf(n) = 2^{2n}. Prove whether f(n)f(n) is in O(2n)O(2^n), and whether f(n)f(n) is in Ω(2n)\Omega(2^n).

(2) Let f(n)=∑i=1n(1/i)f(n) = \sum_{i=1}^{n}(1/i). Prove whether f(n)f(n) is in O(log⁡n)O(\log n), and whether f(n)f(n) is in Ω(log⁡n)\Omega(\log n).

(3) Let ⌊x⌋\lfloor x \rfloor be the largest integer that is equal to or smaller than real number xx. Suppose that f(n)f(n) satisfies that f(1)=1f(1) = 1 and f(n)=f(⌊n/2⌋)+nf(n) = f(\lfloor n/2 \rfloor) + n for n≥2n \geq 2. Prove whether f(n)f(n) is in O(n)O(n), and whether f(n)f(n) is in Ω(n2)\Omega(n^2).


设 nn 为正整数。令 f(n)f(n) 和 g(n)g(n) 表示解决大小为 nn 的问题的计算时间函数。为了提供 f(n)f(n) 的渐近上界和下界,我们分别定义了以下函数集 O(g(n))O(g(n)) 和 Ω(g(n))\Omega(g(n)):

O(g(n))={f(n)∣存在正常数 c0 和 n0 使得 0≤f(n)≤c0 g(n) 对于所有 n≥n0}O(g(n)) = \{f(n) \mid \text{存在正常数 } c_0 \text{ 和 } n_0 \text{ 使得 } 0 \leq f(n) \leq c_0 \, g(n) \text{ 对于所有 } n \geq n_0\}
Ω(g(n))={f(n)∣存在正常数 c0 和 n0 使得 0≤c0 g(n)≤f(n) 对于所有 n≥n0}\Omega(g(n)) = \{f(n) \mid \text{存在正常数 } c_0 \text{ 和 } n_0 \text{ 使得 } 0 \leq c_0 \, g(n) \leq f(n) \text{ 对于所有 } n \geq n_0\}

回答下列问题。

(1) 令 f(n)=22nf(n) = 2^{2n}。证明 f(n)f(n) 是否在 O(2n)O(2^n) 中,以及 f(n)f(n) 是否在 Ω(2n)\Omega(2^n) 中。

(2) 令 f(n)=∑i=1n(1/i)f(n) = \sum_{i=1}^{n}(1/i)。证明 f(n)f(n) 是否在 O(log⁡n)O(\log n) 中,以及 f(n)f(n) 是否在 Ω(log⁡n)\Omega(\log n) 中。

(3) 设 ⌊x⌋\lfloor x \rfloor 为等于或小于实数 xx 的最大整数。假设 f(n)f(n) 满足 f(1)=1f(1) = 1 且 f(n)=f(⌊n/2⌋)+nf(n) = f(\lfloor n/2 \rfloor) + n 对于 n≥2n \geq 2。证明 f(n)f(n) 是否在 O(n)O(n) 中,以及 f(n)f(n) 是否在 Ω(n2)\Omega(n^2) 中。

题目描述​

设 nn 为正整数,f(n),g(n)f(n),g(n) 表示处理规模 nn 问题的运行时间。定义

O(g(n))={f(n)∣∃c0,n0>0, ∀n≥n0, 0≤f(n)≤c0g(n)},O(g(n))=\{f(n)\mid \exists c_0,n_0>0,\ \forall n\ge n_0,\ 0\le f(n)\le c_0g(n)\},
Ω(g(n))={f(n)∣∃c0,n0>0, ∀n≥n0, 0≤c0g(n)≤f(n)}.\Omega(g(n))=\{f(n)\mid \exists c_0,n_0>0,\ \forall n\ge n_0,\ 0\le c_0g(n)\le f(n)\}.

对下列各情形,分别按定义判断所给上界或下界是否成立,并给出证明:

  1. f(n)=22nf(n)=2^{2n} 时,判断 f(n)∈O(2n)f(n)\in O(2^n) 与 f(n)∈Ω(2n)f(n)\in\Omega(2^n)。

  2. f(n)=∑i=1n1if(n)=\sum_{i=1}^{n}\frac1i 时,判断 f(n)∈O(log⁡n)f(n)\in O(\log n) 与 f(n)∈Ω(log⁡n)f(n)\in\Omega(\log n)。

  3. 令 ⌊x⌋\lfloor x\rfloor 表示不超过 xx 的最大整数。若

    f(1)=1,f(n)=f(⌊n/2⌋)+n(n≥2),f(1)=1,\qquad f(n)=f(\lfloor n/2\rfloor)+n\quad(n\ge2),

    判断 f(n)∈O(n)f(n)\in O(n) 与 f(n)∈Ω(n2)f(n)\in\Omega(n^2)。

Kai​

(1)​

Part (a): Prove whether f(n)f(n) is in O(2n)O(2^n)​

To prove f(n)∈O(2n)f(n) \in O(2^n), we need to find constants c0c_0 and n0n_0 such that:

0≤22n≤c0⋅2n for all n≥n0. 0 \leq 2^{2n} \leq c_0 \cdot 2^n \text{ for all } n \geq n_0.

Notice that 22n=(2n)22^{2n} = (2^n)^2. This grows much faster than 2n2^n. To find such c0c_0 and n0n_0:

22n≤c0⋅2n⇒2n≤c0. 2^{2n} \leq c_0 \cdot 2^n \Rightarrow 2^n \leq c_0.

For this to hold for all n≥n0n \geq n_0, c0c_0 would have to be infinite, which is not possible. Therefore,

f(n)=22n∉O(2n). f(n) = 2^{2n} \notin O(2^n).

Part (b): Prove whether f(n)f(n) is in Ω(2n)\Omega(2^n)​

To prove f(n)∈Ω(2n)f(n) \in \Omega(2^n), we need to find constants c0c_0 and n0n_0 such that:

0≤c0⋅2n≤22n for all n≥n0. 0 \leq c_0 \cdot 2^n \leq 2^{2n} \text{ for all } n \geq n_0.

Notice that:

c0⋅2n≤22n⇒c0≤2n. c_0 \cdot 2^n \leq 2^{2n} \Rightarrow c_0 \leq 2^n.

For large nn, 2n2^n grows exponentially, so any fixed positive c0c_0 will be less than 2n2^n for sufficiently large nn. For example, choose c0=1c_0=1 and n0=1n_0=1:

f(n)=22n∈Ω(2n). f(n) = 2^{2n} \in \Omega(2^n).

(2)​

Part (a): Prove whether f(n)f(n) is in O(log⁡n)O(\log n)​

To prove f(n)∈O(log⁡n)f(n) \in O(\log n), we need to find constants c0c_0 and n0n_0 such that:

0≤∑i=1n1i≤c0log⁡n for all n≥n0. 0 \leq \sum_{i=1}^n \frac{1}{i} \leq c_0 \log n \text{ for all } n \geq n_0.

Let's use the properties of the harmonic series. We know that:

∑i=1n1i≤1+∫1n1x dx. \sum_{i=1}^{n} \frac{1}{i} \leq 1 + \int_{1}^{n} \frac{1}{x} \, \mathrm{d}x.

Evaluating the integral, we get:

∫1n1x dx=log⁡n. \int_{1}^{n} \frac{1}{x} \, \mathrm{d}x = \log n.

Thus,

∑i=1n1i≤1+log⁡n. \sum_{i=1}^{n} \frac{1}{i} \leq 1 + \log n.

For sufficiently large nn, the term 1+log⁡n1 + \log n can be bounded by c0log⁡nc_0 \log n for some constant c0≥1c_0 \geq 1. Hence,

f(n)=∑i=1n1i∈O(log⁡n). f(n) = \sum_{i=1}^n \frac{1}{i} \in O(\log n).

Part (b): Prove whether f(n)f(n) is in Ω(log⁡n)\Omega(\log n)​

To prove f(n)∈Ω(log⁡n)f(n) \in \Omega(\log n), we need to find constants c0c_0 and n0n_0 such that:

0≤c0log⁡n≤∑i=1n1i for all n≥n0. 0 \leq c_0 \log n \leq \sum_{i=1}^n \frac{1}{i} \text{ for all } n \geq n_0.

We can compare the harmonic series with the integral from below. Specifically,

∑i=1n1i≥∫1n+11x dx. \sum_{i=1}^{n} \frac{1}{i} \geq \int_{1}^{n+1} \frac{1}{x} \, \mathrm{d}x.

Evaluating the integral, we get:

∫1n+11x dx=log⁡(n+1). \int_{1}^{n+1} \frac{1}{x} \, \mathrm{d}x = \log (n+1).

Thus,

∑i=1n1i≥log⁡(n+1). \sum_{i=1}^{n} \frac{1}{i} \geq \log (n+1).

For sufficiently large nn, log⁡(n+1)\log (n+1) can be bounded from below by c0log⁡nc_0 \log n for some constant c0>0c_0 > 0. Thus, we can choose c0=1c_0 = 1 and n0=1n_0 = 1:

f(n)=∑i=1n1i∈Ω(log⁡n). f(n) = \sum_{i=1}^n \frac{1}{i} \in \Omega(\log n).

(3)​

Part (a): Prove whether f(n)f(n) is in O(n)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. f(n) = f(\lfloor n/2 \rfloor) + n.

This fits the form f(n)=af(n/b)+g(n)f(n) = a f(n/b) + g(n) with a=1a = 1, b=2b = 2, and g(n)=ng(n) = n. The Master Theorem states:

  1. If g(n)=O(nc)g(n) = O(n^c) where c<log⁡bac < \log_b a, then f(n)=Θ(nlog⁡ba)f(n) = \Theta(n^{\log_b a}).
  2. If g(n)=Θ(nlog⁡ba)g(n) = \Theta(n^{\log_b a}), then f(n)=Θ(nlog⁡balog⁡n)f(n) = \Theta(n^{\log_b a} \log n).
  3. If g(n)=Ω(nc)g(n) = \Omega(n^c) where c>log⁡bac > \log_b a, and if ag(n/b)≤kg(n)a g(n/b) \leq k g(n) for some k<1k < 1 and sufficiently large nn, then f(n)=Θ(g(n))f(n) = \Theta(g(n)).

In this case, log⁡ba=log⁡21=0\log_b a = \log_2 1 = 0, and g(n)=ng(n) = n. Since g(n)=Θ(n)g(n)=\Theta(n) has exponent 1>01>0 and g(n/2)=g(n)/2g(n/2)=g(n)/2, case 3 of the Master Theorem applies, giving us:

f(n)=Θ(n). f(n) = \Theta(n).

Thus,

f(n)∈O(n). f(n) \in O(n).

Part (b): Prove whether f(n)f(n) is in Ω(n2)\Omega(n^2)​

We already have from the Master Theorem that f(n)=Θ(n)f(n) = \Theta(n). Therefore, f(n)f(n) is not Ω(n2)\Omega(n^2), because Θ(n)\Theta(n) implies both upper and lower bounds O(n)O(n) and Ω(n)\Omega(n).

Thus,

f(n)∉Ω(n2). f(n) \notin \Omega(n^2).

Knowledge​

递归 主定理 复杂度分析

重点词汇​

  • Asymptotic bounds 渐近界
  • Master Theorem 主定理
  • Harmonic series 调和级数
  • Exponential function 指数函数
  • Recurrence 递归

参考资料​

  1. 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.
  2. Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser. Data Structures and Algorithms in Java, 6th Edition. Wiley. Chapter 5: Recursion.

Reference​