跳到主要内容

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

Author

zephyr

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 0f(n)c0g(n) for all nn0}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 0c0g(n)f(n) for all nn0}\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(logn)O(\log n), and whether f(n)f(n) is in Ω(logn)\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 n2n \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 使得 0f(n)c0g(n) 对于所有 nn0}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 使得 0c0g(n)f(n) 对于所有 nn0}\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(logn)O(\log n) 中,以及 f(n)f(n) 是否在 Ω(logn)\Omega(\log n) 中。

(3) 设 x\lfloor x \rfloor 为等于或小于实数 xx 的最大整数。假设 f(n)f(n) 满足 f(1)=1f(1) = 1f(n)=f(n/2)+nf(n) = f(\lfloor n/2 \rfloor) + n 对于 n2n \geq 2。证明 f(n)f(n) 是否在 O(n)O(n) 中,以及 f(n)f(n) 是否在 Ω(n2)\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:

022nc02n for all nn0. 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:

22nc02n2nc0. 2^{2n} \leq c_0 \cdot 2^n \Rightarrow 2^n \leq c_0.

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

f(n)=22nO(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:

0c02n22n for all nn0. 0 \leq c_0 \cdot 2^n \leq 2^{2n} \text{ for all } n \geq n_0.

Notice that:

c02n22nc02n. c_0 \cdot 2^n \leq 2^{2n} \Rightarrow c_0 \leq 2^n.

For large nn, 2n2^n grows exponentially, so we can choose any positive constant c0c_0 and it will be less than 2n2^n for sufficiently large nn. Thus, we can choose n0=1n_0 = 1 and any c0>0c_0 > 0:

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

(2)

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

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

0i=1n1ic0logn for all nn0. 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=1n1i1+1n1xdx. \sum_{i=1}^{n} \frac{1}{i} \leq 1 + \int_{1}^{n} \frac{1}{x} \, \mathrm{d}x.

Evaluating the integral, we get:

1n1xdx=logn. \int_{1}^{n} \frac{1}{x} \, \mathrm{d}x = \log n.

Thus,

i=1n1i1+logn. \sum_{i=1}^{n} \frac{1}{i} \leq 1 + \log n.

For sufficiently large nn, the term 1+logn1 + \log n can be bounded by c0lognc_0 \log n for some constant c01c_0 \geq 1. Hence,

f(n)=i=1n1iO(logn). f(n) = \sum_{i=1}^n \frac{1}{i} \in O(\log n).

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

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

0c0logni=1n1i for all nn0. 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=1n1i1n+11xdx. \sum_{i=1}^{n} \frac{1}{i} \geq \int_{1}^{n+1} \frac{1}{x} \, \mathrm{d}x.

Evaluating the integral, we get:

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

Thus,

i=1n1ilog(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 c0lognc_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Ω(logn). 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<logbac < \log_b a, then f(n)=Θ(nlogba)f(n) = \Theta(n^{\log_b a}).
  2. If g(n)=Θ(nlogba)g(n) = \Theta(n^{\log_b a}), then f(n)=Θ(nlogbalogn)f(n) = \Theta(n^{\log_b a} \log n).
  3. If g(n)=Ω(nc)g(n) = \Omega(n^c) where c>logbac > \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, logba=log21=0\log_b a = \log_2 1 = 0, and g(n)=ng(n) = n. Since n=Ω(n0)n = \Omega(n^0) and g(n)=ng(n) = n, 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.