4-1(递归式例子)对下列每个递归式,给出T(n)的渐进上界和渐进下界。假定 n ≤ 2 n\leq2 n≤2时T(n)时常数。给出尽量紧确的界,并验证其正确性。
不会主方法的先看以下这篇博客:
https://blog.csdn.net/qq_40512922/article/details/96932368
a. T ( n ) = 2 T ( n / 2 ) + n 4 T(n)=2T(n/2)+n^4 T(n)=2T(n/2)+n4
证明:有 a = 2 , b = 2 , n l o g b a = n a=2,b=2,n^{log_ba}=n a=2,b=2,nlogba=n, f ( n ) = f ( n 4 ) = Ω ( n ϵ + 1 ) f(n)=f(n^4)=\Omega(n^{\epsilon+1}) f(n)=f(n4)=Ω(nϵ+1),其中 ϵ = 3 \epsilon=3 ϵ=3。下面证明正则条件: ∃ c < 1 , a f ( n / b ) ≤ c f ( n ) \exists c<1,af(n/b)\leq cf(n) ∃c<1,af(n/b)≤cf(n)
2 f ( n / 2 ) = n 4 8 ≤ c n 4 2f(n/2)=\frac{n^4}{8} \leq cn^4 2f(n/2)=8n4≤cn4
当 c = 1 / 8 c=1/8 c=1/8时,显然成立。因此 T ( n ) = Θ ( f ( n ) ) = Θ ( n 4 ) T(n)=\Theta(f(n))=\Theta(n^4) T(n)=Θ(f(n))=Θ(n4)
b. T ( n ) = T ( 7 n / 10 ) + n T(n)=T(7n/10)+n T(n)=T(7n/10)+n
证明:有 a = 1 , b = 10 / 7 , n l o g b a = 1 a=1,b=10/7,n^{log_ba}=1 a=1,b=10/7,nlogba=1, f ( n ) = n = Ω ( n ϵ + 0 ) f(n)=n=\Omega(n^{\epsilon+0}) f(n)=n=Ω(nϵ+0),其中 ϵ = 1 \epsilon=1 ϵ=1,下面证明正则条件: ∃ c < 1 , a f ( n / b ) ≤ c f ( n ) \exists c<1,af(n/b)\leq cf(n) ∃c<1,af(n/b)≤cf(n)
f ( 7 n / 10 ) = 7 n / 10 ≤ c n f(7n/10)=7n/10 \leq cn f(7n/10)=7n/10≤cn
当 c = 7 / 10 c=7/10 c=7/10时,显然成立。因此 T ( n ) = Θ ( f ( n ) ) = Θ ( n ) T(n)=\Theta(f(n))=\Theta(n) T(n)=Θ(f(n))=Θ(n)
c. T ( n ) = 16 T ( n / 4 ) + n 2 T(n)=16T(n/4)+n^2 T(n)=16T(n/4)+n2
证明:有 a = 16 , b = 4 , n l o g b a = n 2 a=16,b=4,n^{log_ba}=n^2 a=16,b=4,nlogba=n2, f ( n ) = n 2 = Θ ( n 2 ) f(n)=n^2=\Theta(n^2) f(n)=n2=Θ(n2)。
因此, T ( n ) = Θ ( n 2 l g n ) T(n)=\Theta(n^2lgn) T(n)=Θ(n2lgn)。
d. T ( n ) = 7 T ( n / 3 ) + n 2 T(n)=7T(n/3)+n^2 T(n)=7T(n/3)+n2
证明:有 a = 7 , b = 3 , n l o g b a ≈ n 1.7 a=7,b=3,n^{log_ba}\approx n^{1.7} a=7,b=3,nlogba≈n1.7, f ( n ) = n 2 = Ω ( n 1.7 + ϵ ) f(n)=n^2=\Omega(n^{1.7+\epsilon}) f(n)=n2=Ω(n1.7+ϵ),其中 ϵ = 0.3 \epsilon=0.3 ϵ=0.3,下面证明正则条件。
7 f ( n / 3 ) = 7 n 2 9 ≤ c n 2 7f(n/3)=\frac{7n^2}{9} \leq cn^2 7f(n/3)=97n2≤cn2
当 c = 7 / 9 c=7/9 c=7/9时,显然成立。因此 T ( n ) = Θ ( f ( n ) ) = Θ ( n 2 ) T(n)=\Theta(f(n))=\Theta(n^2) T(n)=Θ(f(n))=Θ(n2)
e. T ( n ) = 7 T ( n / 2 ) + n 2 T(n)=7T(n/2)+n^2 T(n)=7T(n/2)+n2
证明:有 a = 7 , b = 2 , n l o g b a ≈ n 2.8 a=7,b=2,n^{log_ba}\approx n^{2.8} a=7,b=2,nlogba≈n2.8, f ( n ) = n 2 = O ( n 2.8 − ϵ ) f(n)=n^2=O(n^{2.8-\epsilon}) f(n)=n2=O(n2.8−ϵ),其中 ϵ = 0.8 \epsilon=0.8 ϵ=0.8。
因此 T ( n ) = Θ ( n l o g b a ) = Θ ( n l o g 2 7 ) T(n)=\Theta(n^{log_ba})=\Theta(n^{log_27}) T(n)=Θ(nlogba)=Θ(nlog27)
f. T ( n ) = 2 T ( n / 4 ) + n T(n)=2T(n/4)+\sqrt n T(n)=2T(n/4)+n
证明:有
a
=
2
,
b
=
4
,
n
l
o
g
b
a
=
n
0.5
a=2,b=4,n^{log_ba}=n^{0.5}
a=2,b=4,nlogba=n0.5,
f
(
n
)
=
n
0.5
=
Θ
(
n
0.5
)
f(n)=n^{0.5}=\Theta(n^{0.5})
f(n)=n0.5=Θ(n0.5)。
因此,
T
(
n
)
=
Θ
(
f
(
n
)
l
g
n
)
=
Θ
(
n
l
g
n
)
T(n)=\Theta(f(n)lgn)=\Theta(\sqrt{n}lgn)
T(n)=Θ(f(n)lgn)=Θ(nlgn)
g. T ( n ) = T ( n − 2 ) + n 2 T(n)=T(n-2)+n^2 T(n)=T(n−2)+n2
证明:
T
(
n
)
=
∑
i
=
0
n
(
2
i
)
2
=
2
n
(
n
+
1
)
(
2
n
+
1
)
3
+
T
(
0
)
=
Θ
(
n
3
)
T(n)=\sum_{i=0}^{n}{(2i)^2}=\frac{2n(n+1)(2n+1)}{3}+T(0) = \Theta(n^3)
T(n)=i=0∑n(2i)2=32n(n+1)(2n+1)+T(0)=Θ(n3)