Professional Documents
Culture Documents
3-1x
* When comparing the complexities of algorithms, 3-1a
we compare their rates of growth.
"最大項"
* "algo. A is better than algo B" means
"A is faster when n is sufficiently large"
*如果 f, g
的最大項不一樣, 分出勝負
調整係數無法改變大小關係
f(n) = n3 + n2 – 100n 大 10-6 f(n) 大
g(n) = 30n2 + 100n 小 106 g(n) 小
* 如果 f, g 的最大項一樣, 由最大項係數決定
調整係數可以改變大小關係
f(n) = 4n3 + n2 – 100n 大 f(n) 小
g(n) = 3n3 + 5n2 + 100n 小 106 g(n) 大
f, g: two functions
調整 g 係數可讓 g f 也可讓 g f
f的最大項"="g的最大項
f的成長率"="g的成長率
調整 g 係數可讓 f g
f的最大項""g的最大項
f的成長率""g的成長率
調整 g 係數可讓 g f
f的最大項""g的最大項
f的成長率""g的成長率
3-1y
method 1. try n0 = 1, 2, 3, ...
n0 n0 n0
n 1 2 3 4 5 6 7 8
3-6/n -3 0 1 1.5 1.8 2 2.14 2.25
c1 ~c1c2~c1c2~ c2
try
- if n0 = 1, positive c1 and c2 exist ?
- if n0 = 2, positive c1 and c2 exist ?
- if n0 = 3, positive c1 and c2 exist ?
3-1y
method 2. choose c1, c2 and then find n0
n 1 2 3 4 5 6 7 8
3-6/n -3 0 1 1.5 1.8 2 2.14 2.25
3-1y
f, g: two functions
調整 g 係數可讓 g f 也可讓 g f
f的最大項"="g的最大項
f的成長率"="g的成長率 f= (g)
調整 g 係數可讓 f g
f的最大項""g的最大項
f的成長率""g的成長率 f= O(g)
調整 g 係數可讓 g f
f的最大項""g的最大項
f的成長率""g的成長率 f= (g)
3-3x
o(g(n)) = Ο(g(n)) \ Θ(g(n)) ???
Mathematically, no!
g(n) = n2 f = O(g), but not o or
Algorithmically, yes!
Because, it is reasonable to assume that
T(n) is "regular" for large n.
3-3y
functions: O
real numbers:
Transitivity
a b, b c f(n) = O(g(n)), g(n) = O(h(n))
a c f(n) = O(h(n))
Reflexivity a a f(n) = (f(n))
3-4x
time complexities
1 lg* n lglg n lg n n n n2 n3 nk 2n
2
polynomial exponential
3-4y
1
x
k
( x 1) 等比會收斂 !
k 0
1 x
3-5x