Professional Documents
Culture Documents
- INDIVIDU
jawab exercise (1) dan (2) di slide ke-31 dan 32 ini ppt
nya
kirim ke email bu astuti yg ini lg.astuti@gmail.com
deadline sebelum UAS
-KELOMPOK
tambahkan pertanyaan ama pembahasaan dr yg
temen2/ibunya tanyain pas presentasi, isi nim nama
penanya trus
buat komplekitas algoritma yg lengkap dr presentasi
yg kalian bawain, kirim juga ke email deadline
sebelum UAS
Contents
Asymptotic Notations:
O (big oh)
(big omega)
(big theta)
In the following
discussion
t(n) & g(n): any nonnegative functions
defined on the set of natural numbers
t(n) analgorithmsrunningtime
Usually indicated by its basic operation count
C(n)
O(g(n)): Informally
O(g(n)) is a set of all functions with a
smaller or same order of growth as g(n)
Examples:
n O(n2); 100n + 5 O(n2)
n (n-1) O(n2)
n3 O(n2); 0.0001 n3 O(n2); n4+n+1 O(n2)
(g(n)): Informally
(g(n)) is a set of all functions with a
larger or same order of growth as g(n)
Examples:
n3 (n2)
n (n-1) (n2)
100n + 5 (n2)
(g(n)): Informally
(g(n)) is a set of all functions with a
same order of growth as g(n)
Examples:
an2+bn+c; a>0 (n2); n2+sin n (n2)
n (n-1) (n2); n2+log n (n2)
100n + 5 (n2); n3 (n2)
O-notation: Formally
DEF1: A function t(n) is said to be in
O(g(n)), denoted t(n) O(g(n)), if t(n) is
bounded above by some constant multiple
of g(n) for all large n
doesn't
matter
t(n)
n0
-notation: Formally
DEF2: A function t(n) is said to be in
(g(n)), denoted t(n) (g(n)), if t(n) is
bounded below by some constant multiple
of g(n) for all large n
doesn't
matter
cg(n)
n0
-notation: Formally
DEF3: A function t(n) is said to be in
(g(n)), denoted t(n) (g(n)), if t(n) is
bounded both above and below by some
constant multiple of g(n) for all large n
doesn't
matter
t(n)
n0
c2g(n)
Class: 1
Name: constant
Comment:
Short of best-case efficiency
Very few reasonable examples can be given
algsrunningtimetypicallygoestoinfinity
when its input size grows infinitely large
Class: log n
Name: logarithmic
Comment:
Typically,aresultofcuttingaproblemssize
by a constant factor on each iteration of the
algorithm
Logarithmic alg cannot take into account all its
input or even a fixed fraction of it: any
algorithm that does so will have at least linear
running time
Class: n
Name: linear
Comment:
Algorithms that scan a list of size n (e.g.
sequential search) belong to this class
Class: n log n
Name: n-log-n
Comment:
Many divide-and-conquer algorithms,
including merge sort and quick sort in the
average case, fall into this class
Class: n2
Name: quadratic
Comment:
Typically, characterizes efficiency of
algorithms with two embedded loops
Standard examples: elementary sorting
algorithms and certain operations on n-by-n
matrices
Class: n3
Name: cubic
Comment:
Typically, characterizes efficiency of
algorithms with three embedded loops
Several nontrivial algorithms from linear
algebra fall into this class
Class: 2n
Name: exponential
Comment:
Typical for algorithms that generate all
subsets of an n-element set
Thetermexponentialisoftenusedtoinclude
this and faster orders of growth as well
Class: n!
Name: factorial
Comment:
Typical for algorithms that generate all
permutations of an n-element set
Useful Property
Theorem:
If t1(n) O(g1(n)) and t2(n) O(g2(n)),
then t1(n) + t2(n) O(max{g1(n), g2(n)})
The analogous assertions are true for the
and notations as well
Example
Alg to check whether an array has
identical elements:
Sort the array
Scan the sorted array to check its
consecutive elements for equality
0implies
that
has
a
smalle
OoG
t(n)
g(n
t
(
n
)
lim
cimplies
that
has
the
same
OoG
t(n)
as
g(n
g
(
n
)
implies
that
has
a
larger
OoG
t(n)
g(n
Limit-based: why
convenient?
It can take advantage of the powerful
calculus techniques developed for
computing limits, such as
LHopitalsrule
t(
n
)
t'(
n
)
lim
lim
n
g
(
n
) n
g
'(
n
)
Stirlingsformula
for
n
!
2
n
large
valu
of
n
n
n
e
Example (1)
Compare OoG of n(n-1) and n2.
2
n
(
n
1
)1
n
n
1 11
lim
lim
lim
1
n
2
2
n
n 2 n2
2
1
2
lim
lim
2
log
e
lim
0
2
1
n
n
n (
n
)' 2
n
Example (2)
Compare OoG of n! and 2n.
n
n
! 2
n
n
lim
lim
lim
2
n
lim
2
n
2 2
2
e
2
e
n
n
n
e
n
n n
n
n
n
n
Exercises (1)
True or false:
n(n+1)/2 O(n3)
n(n+1)/2 O(n2)
n(n+1)/2 (n3)
n(n+1)/2 (n)
Exercises (2)
1. Prove that every polynomial
p(n) = aknk + ak-1nk-1 ++a0 with ak > 0
belongs to (nk)
Prove that exponential functions an have
different orders of growth for different
values of base a > 0