文章目录
渐近记号-算法
Big-Oh(渐近上界)
∙ \bullet ∙ O O O-notation: For a given function g ( n ) (n) (n), we denote O ( g ( n ) ) O(\mathfrak{g}(n)) O(g(n)) the set of functions O ( O( O(g ( n ) ) = { f ( n ) : (n))=\{f(n): (n))={f(n):there exist positive constants c c c and n 0 n_0 n0 such that 0 ≤ f ( n ) ≤ c g ( n ) 0\leq f(n)\leq cg(n) 0≤f(n)≤cg(n) for all n ≥ n 0 } n\geq n_0\} n≥n0}
Big-Omega(渐近下界)
∙
\bullet
∙
Ω
\Omega
Ω-notation: For a given function
g
(
n
)
g(n)
g(n), we denote
Ω
(
g
(
n
)
)
\Omega(\mathfrak{g}(n))
Ω(g(n)) the set of functions
Ω
(
\Omega(
Ω(g
(
n
)
)
=
{
f
(
n
)
:
(n))=\{f(n):
(n))={f(n):there exist positive constants
c
c
c and
n
0
n_0
n0 such that
0
≤
c
0\leq c
0≤cg
(
n
)
≤
f
(
n
)
(n)\leq f(n)
(n)≤f(n) for all
n
≥
n
0
}
n\geq n_0\}
n≥n0}
Big-Theta(渐近紧界)
∙
\bullet
∙
Θ
\Theta
Θ-notation: For a given function
g
(
n
)
g(n)
g(n),we denote
Θ
(
g
(
n
)
)
\Theta(\mathfrak{g}(n))
Θ(g(n)) the set of functions
Θ
(
\Theta(
Θ(g
(
n
)
)
=
{
f
(
n
)
:
(n))=\{f(n):
(n))={f(n):there exist positive constants
c
1
,
c
2
c_1,c_2
c1,c2 and
n
0
n_0
n0 such that
0
≤
c
1
0\leq c_1
0≤c1g
(
n
)
≤
f
(
n
)
≤
c
2
(n)\leq f(n)\leq c_2
(n)≤f(n)≤c2g
(
n
)
(n)
(n) for all
n
≥
n
0
}
n\geq n_0\}
n≥n0}
∙ \bullet ∙ Theorem: For any two functions f ( n ) f(n) f(n) and g ( n ) (n) (n), we have f ( n ) = Θ ( f(n)=\Theta( f(n)=Θ(g ( n ) ) (n)) (n)) if and only if f ( n ) = O ( g ( n ) ) f(n)=O\left(\mathrm{g}(n)\right) f(n)=O(g(n)) and f ( n ) = f(n)= f(n)= Ω ( g ( n ) ) . \Omega\left(\mathrm{g}(n)\right). Ω(g(n)).
Example
Example: How to show that n 2 / 2 − 3 n = Θ ( n 2 ) ? We must determine positive constants c 1 , c 2 a n d n 0 such that c 1 n 2 ≤ n 2 / 2 − 3 n ≤ c 2 n 2 ⇒ c 1 ≤ 1 / 2 − 3 / n ≤ c 2 By choosing c 1 = 1 / 14 , c 2 = 1 / 2 , a n d n 0 = 7 , we can verify that n 2 / 2 − 3 n = 9 ( n 2 ) The key is some choice exists. \begin{aligned}&\text{Example: How to show that }n^2/2-3n=\Theta(n^2)?\\&\text{We must determine positive constants }c_1,c_2\mathrm{~and~}n_0\text{ such that}\\&c_1n^2\leq n^2/2-3n\leq c_2n^2\\&\Rightarrow c_1\leq1/2-3/n\leq c_2\\&\text{By choosing }c_1=1/14,c_2=1/2,\mathrm{and~}n_0=7,\text{we can verify}\\&\text{that }n^2/2-3n=9(n^2)\\&\text{The key is some choice exists.}\end{aligned} Example: How to show that n2/2−3n=Θ(n2)?We must determine positive constants c1,c2 and n0 such thatc1n2≤n2/2−3n≤c2n2⇒c1≤1/2−3/n≤c2By choosing c1=1/14,c2=1/2,and n0=7,we can verifythat n2/2−3n=9(n2)The key is some choice exists.
Small-Oh(非渐近紧上界)
Small-Omega(非渐近紧下界)
简记
An interesting fact about logarithm
l
o
g
b
1
n
=
O
(
l
o
g
b
2
n
)
log_{b_1}n=O(log_{b_2}n)
logb1n=O(logb2n)
For any constant b
1
>
1
_1>1
1>1 and
b
2
>
1.
\mathfrak{b}_2>1.
b2>1.
Because of the above, in computer science, we omit all the constant logarithm bases in big-O. For example, instead of
O
(
log
2
\mathcal{O}(\log_2
O(log2 n), we will simply write
O
(
log
\mathcal{O}(\log
O(log n)
∙
\bullet
∙ Essentially, this says that"you are welcome to put any constant base there, and it will be the same
asymptotically" . \textbf{asymptotically" . } asymptotically" .
⋅ \cdot ⋅ Obviously, Ω , Θ \Omega,\Theta Ω,Θ also have this property.