1. 知识梳理
-
渐近记号与定义
{ Θ 、 Ω 、 O 、 o 、 ω } ∼ { = 、 ≥ 、 ≤ 、 < 、 > } \{\Theta 、 \Omega、O、o、\omega \} \sim \ \{=、\ge、\le、\lt、\gt\} { Θ、Ω、O、o、ω}∼ { =、≥、≤、<、>}- f ( n ) = Θ ( g ( n ) ) → { f ( n ) : t h e r e e x i s t p o s i t i v e c o n s t a n t s c 1 , c 2 a n d n 0 s u c h t h a t 0 ≤ c 1 g ( n ) ≤ f ( n ) ≤ c 2 g ( n ) f o r a l l n ≥ n 0 } f(n) = \Theta(g(n)) \rightarrow \{f(n): there \ exist \ positive \ constants \ c_1,c_2 \ and \ n_0 \ such \ that \ 0 \le c_1g(n) \le f(n) \le c_2g(n) \ for\ all \ n \ge n_0 \} f(n)=Θ(g(n))→{ f(n):there exist positive constants c1,c2 and n0 such that 0≤c1g(n)≤f(n)≤c2g(n) for all n≥n0}
- f ( n ) = Ω ( g ( n ) ) → { f ( n ) : t h e r e e x i s t p o s i t i v e c o n s t a n t s c a n d n 0 s u c h t h a t 0 ≤ c g ( n ) ≤ f ( n ) f o r a l l n ≥ n 0 } f(n) = \Omega(g(n)) \rightarrow \{f(n): there \ exist \ positive \ constants \ c \ and \ n_0 \ such \ that \ 0 \le cg(n) \le f(n) \ for\ all \ n \ge n_0 \} f(n)=Ω(g(n))→{ f(n):there exist positive constants c and n0 such that 0≤cg(n)≤f(n) for all n≥n0}
- f ( n ) = O ( g ( n ) ) → { f ( n ) : t h e r e e x i s t p o s i t i v e c o n s t a n t s c a n d n 0 s u c h t h a t 0 ≤ f ( n ) ≤ c g ( n ) f o r a l l n ≥ n 0 } f(n) = O(g(n)) \rightarrow \{f(n): there \ exist \ positive \ constants \ c \ and \ n_0 \ such \ that \ 0 \le f(n) \le cg(n)\ for\ all \ n \ge n_0 \} f(n)=O(g(n))→{ f(n):there exist positive constants c and n0 such that 0≤f(n)≤cg(n) for all n≥n0}
- f ( n ) = o ( g ( n ) ) → { f ( n ) : f o r a n y p o s i t i v e c o n s t a n t c > 0 , t h e r e e x i s t s a c o n s t a n t n 0 > 0 s u c h t h a t 0 ≤ f ( n ) < c g ( n ) f o r a l l n ≥ n 0 } f(n) = o(g(n)) \rightarrow \{f(n): for \ any \ positive \ constant \ c \gt 0,there \ exists \ a \ constant \ n_0\gt 0 \ such \ that \ 0 \le f(n) \lt cg(n)\ for\ all \ n \ge n_0 \} f(n)=o(g(n))→{ f(n):for any positive constant c>0,there exists a constant n0>0 such that 0≤f(n)<cg(n) for all n≥n0}
- f ( n ) = ω ( g ( n ) ) → { f ( n ) : f o r a n y p o s i t i v e c o n s t a n t c > 0 , t h e r e e x i s t s a c o n s t a n t n 0 > 0 s u c h t h a t 0 ≤ c g ( n ) < f ( n ) f o r a l l n ≥ n 0 } f(n) = \omega(g(n)) \rightarrow \{f(n): for \ any \ positive \ constant \ c \gt 0,there \ exists \ a \ constant \ n_0 \gt 0 \ such \ that \ 0 \le cg(n) \lt f(n) \ for\ all \ n \ge n_0 \} f(n)=ω(g(n))→{ f(n):for any positive constant c>0,there exists a constant n0>0 such that 0≤cg(n)<f(n) for all n≥n0}
-
记号的性质
- 传递性(Transitivity): f ( n ) = Θ ( g ( n ) ) a n d g ( n ) = Θ ( h ( n ) ) ⟹ f ( n ) = Θ ( h ( n ) ) f(n) =\Theta(g(n)) \ and \ g(n)=\Theta(h(n)) \implies f(n) =\Theta(h(n)) f(n)=Θ(g(n)) and g(n)=Θ(h(n))⟹f(n)=Θ(h(n)),对以上记号均成立
- 自反性(Reflexivity): f ( n ) = Θ ( f ( n ) ) f(n) = \Theta(f(n)) f(n)=Θ(f(n)),对 ω 、 o \omega、o ω、o不成立
- 对称性(Symmetry): f ( n ) = Θ ( g ( n ) ) ⟺ g ( n ) = Θ ( f ( n ) ) f(n) =\Theta(g(n)) \iff g(n) =\Theta(f(n)) f(n)=Θ(g(n))⟺g(n)=Θ(f(n)),只适合 Θ \Theta Θ记号
- 转置对称性(Transpose symmetry): f ( n ) = O ( g ( n ) ) ⟺ g ( n ) = Ω ( f ( n ) ) f(n) = O(g(n)) \iff g(n) = \Omega(f(n)) f(n)=O(g(n))⟺g(n)=Ω(f(n)),对于 ω 、 o \omega、o ω、o也适用
注:不是所有函数都可以渐近比较,即 f ( n ) = O ( g ( n ) ) f(n)=O(g(n)) f(n)=O(g(n))等比较可能不成立, E x : n a n d n 1 + s i n n Ex:n \ and \ n^{1+sin\ n} Ex:n and n1+sin n
-
标记记号与常用函数
- 一些取整式子(待证明):
- ⌈ ⌈ x / a ⌉ b ⌉ = ⌈ x a b ⌉ \bm{\lceil \frac{\lceil x/a \rceil}{b}\rceil = \lceil \frac{x}{ab}\rceil} ⌈b⌈x/a⌉⌉=⌈abx⌉
- ⌊ ⌊ x / a ⌋ b ⌋ = ⌊ x a b ⌋ \bm{\lfloor \frac{\lfloor x/a \rfloor}{b}\rfloor = \lfloor \frac{x}{ab}\rfloor} ⌊b⌊x/a⌋⌋=⌊abx⌋
- ⌈ a b ⌉ ≤ a + ( b − 1 ) b \bm{\lceil \frac{a}{b}\rceil \le \frac{a + (b-1)}{b}} ⌈ba⌉≤ba+(b−1)
- ⌈ a b ⌉ ≥ a − ( b − 1 ) b \bm{\lceil \frac{a}{b}\rceil \ge \frac{a - (b-1)}{b}} ⌈ba⌉≥ba−(b−1)
- 多项式:若对于某个常量 k k k,有 f ( n ) = O ( n k ) f(n) = O(n^k) f(n)=O(nk),则称 f ( n ) f(n) f(n)是多项式有界的。
- 指数:当 ∣ x ∣ ≤ 1 |x| \le1 ∣x∣≤1时,近似有: 1 + x ≤ e x ≤ 1 + x + x 2 1+x \le e^x \le 1+x+x^2 1+x≤ex≤1+x+x2
- 对数:
- a l o g b c = c l o g b a a^{log_bc} = c^{log_ba} alogbc=clogba;
- 换底公式;
- 对 x > − 1 x \gt -1 x>−1, x 1 + x ≤ l n ( 1 + x ) ≤ x \frac{x}{1+x} \le ln(1+x) \le x 1+xx≤ln(1+x)≤x;
- 多对数有界:对于某个常量 k k k, f ( n ) = O ( l g k n ) f(n) = O(lg^kn) f(n)=O(lgkn);
- 阶乘:
- 斯特林近似公式: n ! = 2 π n ( n e ) n ( 1 + Θ ( 1 n ) ) n! = \sqrt{2\pi n}(\frac{n}{e})^n(1+\Theta(\frac{1}{n})) n!=2πn(en)n(1+Θ(n1))
- 多对数、多项式、指数函数间速率比较: n b = o ( a n ) f o r a l l a > 1 n^b = o(a^n) \ for \ all \ a\gt1 nb=o(an) for all a>1 ; l g b n = o ( n a ) f o r a l l a > 0 lg^bn = o(n^a) \ for \ all \ a\gt 0 lgbn=o(na) for all a>0
- 多重函数:
f ( i ) ( x ) = { n if i = 0 f ( f ( i − 1 ) ( n ) ) if i > 0 f^{(i)}(x)= \begin{cases} n &\text{if i = 0}\\ f(f^{(i-1)}(n))&\text{if i$\gt$0 } \end{cases} f(i)(x)={ nf(f(i−1)(n))if i = 0if i>0 - 多重对数函数: l g ∗ n = m i n { i ≥ 0 : l g ( i ) n ≤ 1 } lg^*n = min\{i \ge 0: lg^{(i)}n \le 1\} lg∗n=min{ i≥0:lg(i)n≤1}
- 斐波那契数:
- 黄金分割率: ϕ = 1 + 5 2 \phi=\frac{1+\sqrt{5}}{2} ϕ=21+5,共轭数 ϕ ^ = 1 − 5 2 \hat{\phi} = \frac{1-\sqrt{5}}{2} ϕ^=21−5
- F i = ϕ i − ϕ ^ i 5 F_i = \frac{\phi^i - \hat{\phi}^i}{\sqrt{5}} Fi=5ϕi−ϕ^i;
- ∣ ϕ ^ ∣ < 1 → ∣ ϕ ^ ∣ 5 < 1 5 < 1 2 → F i = ⌊ ϕ i 5 + 1 2 ⌋ |\hat{\phi}| \lt1 \rightarrow \frac{|\hat{\phi}|}{\sqrt{5}} \lt \frac{1}{\sqrt{5}} \lt \frac{1}{2} \rightarrow F_i = \lfloor \frac{\phi^i}{\sqrt{5}} + \frac{1}{2} \rfloor ∣ϕ^∣<1→5∣ϕ^∣<51<21→Fi=⌊5ϕi+21⌋
- 一些取整式子(待证明):
2. 课堂笔记
主要看递归式求解方法,有些内容(如主方法的证明)在第四章。
3. 重点习题
练习题
3.1-2、3.1-3、3.2-3、*3.2-4、*3.2-5
思考题
全部(3-1 → \rightarrow → 3-6)