1 Algorithms CSCI 235, Fall 2015 Lecture 4 Asymptotic Analysis II.
-
Upload
derrick-harmon -
Category
Documents
-
view
218 -
download
0
Transcript of 1 Algorithms CSCI 235, Fall 2015 Lecture 4 Asymptotic Analysis II.
1
Algorithms
CSCI 235, Fall 2015Lecture 4
Asymptotic Analysis II
2
Last time...
Say that f is: Notation ApproximatelyLooselylittle omega g f=(g) f is way bigger than g f>gomega g f=(g) f is at least as big as g f>=gtheta g f=(g) f is about the same as g f=goh g f=O(g) f is at most as big as g f<=glittle oh g f=o(g) f is way smaller than g f<g
3
Relationships between O,o,,,
(g)(g)
(g)
(g)
(g)
€
(g) ⊂Ω(g)
€
o(g) ⊂O(g)
is a subset of
biggerf
smallerf
4
and
if f = (g) then f = (g)
Why?
Definition of (n):
Definition of (n):
€
(g(n))= { f (n) | ∀ positive constants c, ∃ n0 > 0
such that ∀n ≥ n0 0 ≤ cg(n)< f (n)}
€
(g(n)) = { f (n) | ∃ positive constants c, n0
such that ∀n ≥ n0 0 ≤ cg(n) ≤ f (n)}
If f=(g) is it necessarily true that f=(g)?
5
O and o
if f = o(g) then f = (g)
Why?
Definition of (n):
Definition of (n):
If f=(g) is it necessarily true that f=(g)?
€
o(g(n))= { f (n) | ∀ positive constants c, ∃ n0 > 0
such that ∀n ≥ n0 0 ≤ f (n)< cg(n)}
€
O(g(n)) = { f (n) | ∃ positive constants c, n0
such that ∀n ≥ n0 0 ≤ f (n) ≤ cg(n)}
6
is a subset of and of O
(g) union (g) is a subset of (g)
€
(g)∪Θ(g) ⊂Ω(g)
(g) union (g) is a subset of (g)
€
o(g)∪Θ(g) ⊂O(g)
(g)
(g)(g)
(g)
(g)
7
is the intersection of O and
€
(g) = Ω(g) ∩O(g)
In other words:f=(g) if and only if f=O(g) and f= (g)
why?
€
O(g(n)) = { f (n) | ∃ positive constants c, n0
such that ∀n ≥ n0 0 ≤ f (n) ≤ cg(n)}
€
(g(n)) = { f (n) | ∃ positive constants c, n0
such that ∀n ≥ n0 0 ≤ cg(n) ≤ f (n)}
€
(g(n)) = { f (n) | ∃ positive constants c1, c2, n0
such that ∀n ≥ n0 0 ≤ c1g(n) ≤ f (n) ≤ c2g(n)}
8
Symmetric relationships
f = (g) if and only if g = o(f)why?
f = (g) if and only if g = O(f)why?
f = (g) if and only if g = (f)why?
9
Example 1What is the relationship between f and g?
€
f (n) = 5 −1
2n
g(n) =1
What happens if you change the coefficients?
10
Example 2
What is the relationship between f and g?
€
f (n) = n −1
2n
g(n) =1
11
Example 3
Can we have a function that is in O(g) but not o(g) or (g)?
€
f (n) = { n if n is odd1 if n is even
Consider:
a) g(n) = 1
b) g(n) = n
12
Helpful hints
1) Not every pair of functions is comparable
2) It may be easier to test for o(g) and (g). Try these first and then try O, and .
3) Sometimes you can deduce several relationships from the knowledge of only 1. For example: if a function is o(g) it is also O(g), but never (g), (g) or (g).
4) When in doubt, graph the functions.