Escolar Documentos
Profissional Documentos
Cultura Documentos
Pertemuan 04
Contents
Asymptotic Notation
Asymptotic Notation
Think of n as the number of records we wish to
Asymptotic Notation
Memperkirakan formula untuk run-time
Misalkan:
T(n) = 5n2 + 6n + 25
T(n) proporsional untuk ordo n2 untuk data yang sangat
besar.
Asymptotic Notation
Indikator efisiensi algoritma berdasar pada
OoG pada basic operation suatu algoritma.
Penggunaan notasi sebagai pembanding
urutan OoG:
O (big oh)
(big omega)
(big theta)
Example
Example: f(n) = n2 - 5n + 13.
The constant 13 doesn't change as n grows,
so it is not crucial. The low order term, -5n,
doesn't have much effect on f compared to
the quadratic term, n2.
We will show that f(n) = (n2) .
Example (cont.)
Q: What does it mean to say f1(n) = (1)?
A: f1(n) = (1) means after a few n, f1 is
bounded above & below by a constant.
Q: What does it mean to say f2(n) = (n log n)?
Big-Oh
The O symbol was introduced in 1927 to
indicate relative growth of two functions based
on asymptotic behavior of the functions now
used to classify functions and families of
functions
In general a function
f(n) is O(g(n)) if positive constants c and n0 such
that f(n) c g(n) n n0
c g(n)
f(n)
g(n)
n0
4 g(n) = 4n2
= 3n2 + n2
3n2 + 9 for all n 3
> 3n2 + 5
= f(n)
Thus, f(n)=O(g(n)).
f(n)=3n2+5
g(n)=n2
Exercise on O-notation
Show that 3n2+2n+5 = O(n2)
10 n2 = 3n2 + 2n2 + 5n2
3n2 + 2n + 5 for n 1
c = 10, n0 = 1
Tugas 1 : O-notation
f1(n) = 10 n + 25 n2
f2(n) = 20 n log n + 5 n
f3(n) = 12 n log n + 0.05 n2
f4(n) = n1/2 + 3 n log n
O(n2)
O(n log n)
O(n2)
O(n log n)
Tugas 2
Kompleksitas waktu :
untuk kasus basis, tidak ada operasi perkalian (0)
untuk kasus rekurens, kompleksitas waktu diukur dari jumlah perkalian (1)
ditambah kompleksitas waktu untuk faktorial (n-1)
g(n)=n
g(n)/4 = n2/4
= n2/2 n2/4
n2/2 9 for all n 6
< n2/2 7
Thus, f(n)= (g(n)).
f(n)=n2/2-7
c g(n)=n2/4
c2 g(n)
f(n)
c1 g(n)
n0
Intuitively,
o() is like <
O() is like
() is like >
() is like
() is like =
Examples (cont.)
3. Suppose a program P is O(n3), and a program Q
is O(3n), and that currently both can solve
problems of size 50 in 1 hour. If the programs are
run on another system that executes exactly 729
times as fast as the original system, what size
problems will they be able to solve?
Example (cont.)
n3 = 503 729
n = 3 503 * 729
n =
50 3 3 729
n = 50 9
n = 50 9 = 450
3n = 350 729
n = log3 (729 350)
n = log3(729) + log3 350
n = 6 + log3 350
n = 6 + 50 = 56
Tugas 3
(a) 0.5n2 - 5n + 2 = ( n2). (True or False)
Let c = 0.25 and n0 = 25.
(b) 0.5 n2 - 5n + 2 = O( n2). (True or False)
Let c = 0.5 and n0 = 1.
(c) 0.5 n2 - 5n + 2 = ( n2) (True or False)
from (a) and (b) above.
Use n0 = 25, c1 = 0.25, c2 = 0.5 in the definition.
f(n) = n
f(n) = log(n)
f(n) = n log(n)
f(n) = n^2
f(n) = n^3
f(n) = 2^n
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
f(n) = n
f(n) = log(n)
f(n) = n log(n)
f(n) = n^2
f(n) = n^3
f(n) = 2^n
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
f(n) = n
f(n) = log(n)
f(n) = n log(n)
f(n) = n^2
f(n) = n^3
f(n) = 2^n
0
1
11
13
15
17
19
4000
f(n) = n
f(n) = log(n)
3000
f(n) = n log(n)
f(n) = n^2
2000
f(n) = n^3
f(n) = 2^n
1000
0
1
11
13
15
17
19
Thank You !