BigO Analysis
-
Upload
laura-craig -
Category
Documents
-
view
220 -
download
0
Transcript of BigO Analysis
-
8/12/2019 BigO Analysis
1/10
Growth of Functions and Asymptotic Notation
Overview
Study a way to describe behavior of functions in the limit ...
asymptotic efficiency Describe growth of functions
Focus on whats important by abstracting lower-order terms andconstant factors
How we indicate running times of algorithms
A way to compare sizes of functions
http://find/ -
8/12/2019 BigO Analysis
2/10
O-notation
Asymptotic upper bound O-notation
f(n) =O(g(n))
if there exists constants c and n0 such that
0 f(n) c g(n) forn n0
say: g(n) is an asymptotic upper bound for f(n). Example:
2n + 10 =O(n2), pick c= 1 and n0 = 5
http://find/ -
8/12/2019 BigO Analysis
3/10
More on O-notation
Thing ofO(g(n)) as a set of functions
O(g(n)) ={f(n) : c, n0
such that 0 f(n) c g(n) forn n0
} Examples of functions in O(n2):
n2 +nn2 + 1000n1000n2 + 1000n
n/1000n2/ lg n
O-notation is an upper-bound notation. Makes no sense to say f(n) isat leastO(g(n))? (why?)
http://find/ -
8/12/2019 BigO Analysis
4/10
-notation
Asymptotic lower bound -notation
f(n) =(g(n))
if there exists constants c and n0 such that
0 c g(n) f(n) forn n0
say: g(n) is an asymptotic lower bound for f(n). Example:
n= (lgn), pick c= 1 and n0 = 16
http://find/ -
8/12/2019 BigO Analysis
5/10
More on -notation
Thing of(g(n)) as a set of functions
(g(n)) ={f(n) : c, n0
such that 0 c g(n) f(n) forn n0
} Examples of functions in (n2):
n2
n2 +nn2 n
1000n2 + 1000n1000n2 1000nn2.00001
n2 lg nn3
http://find/ -
8/12/2019 BigO Analysis
6/10
-notation
Asymptotic tight bound -notation
f(n) =(g(n))if there exists constants c1, c2 and n0 such that
0 c1 g(n) f(n) c2g(n) forn n0
say: g(n) is an asymptotic tight bound for f(n). Example:
1
2n2 2n= (n2), pick c1 = 14 c2 =
1
2 and n0 = 8.
Ifp(n) =
d
i=1ain
i and ad >0, then p(n) =O(nd)
http://find/ -
8/12/2019 BigO Analysis
7/10
More on -notation
Thing of(g(n)) as a set of functions
(g(n)) ={f(n) :
c1, c2, n0 such that 0
c1g(n)
f(n)
c2g(n) forn
Examples of functions in (n2):n2
n2 +nn2 n
1000n2 + 1000n1000n2 1000n
http://find/ -
8/12/2019 BigO Analysis
8/10
Theorem
Theorem. O and iff.
http://find/ -
8/12/2019 BigO Analysis
9/10
Using limits for comparing orders of growth
In order to determine the relationship between f(n) and g(n), it is oftenusefuly to examine
limn f(n)g(n) =L
The possible outcomes:
1. L= 0: f(n) =O(g(n))
2. L= : f(n) =(g(n))
3. L= 0 is finite: f(n) =(g(n))
4. There is no limit: this technique cannot be used to determine theasymptotic relationship between f(n) and g(n).
http://find/ -
8/12/2019 BigO Analysis
10/10
Examples
1. f(n) =n2 and g(n) =n lgn
n2 =(n lg n)
2. f(n) =n100 and g(n) = 2n
n100 =O(2n)
3. f(n) = 10n(n+ 1) and g(n) =n2
10n(n+ 1) =(n2)
http://find/