Big-O & Binary Relations 1 Third Hour Exam Study Sheet I. Big

advertisement
CSC224/226 –Test 3 Review – Big-O & Binary Relations
Third Hour Exam Study Sheet
I.
Big-O
A.
Definition
B.
Give Big-O, Big-Theta, Big-Omega of functions
C.
Using definition of Big-O to prove that the given Big-O is the correct
one for the given function
D.
If f(x) is in O(g(x)), draw a picture of the relationship between f(x)
and g(x)
II.
Binary Relations
A.
B.
C.
D.
E.
F.
G.
III.
Definition
Properties (reflexive, irreflexive, non-reflexive, symmetric,
antisymmetric, asymmetric, transitive)
Matrix Representation
Inverse Relation
Composite Relations
Closure Properties
Special Types (equivalence relations, partially ordered sets)
Induction
A.
Prove closed form is true for a recursion, by induction
B.
Prove inequalities are true by induction
C.
Prove Big-O by induction
1
CSC224/226 –Test 3 Review – Big-O & Binary Relations
Third Hour Exam Practice
These problems are intended as extra practice for the third hour exam. They do
not have to be turned in and will not be collected. However, they are
recommended, since the same types of problems will be encountered on the
test. A solution for each problem is attached.
Give a Big-O estimate for each of the following functions. (Give the function of
smallest order.)
1.
nlog(n2 + 1) + n2 logn
2.
(nlogn + 1)2 + (logn + 1)(n2 + 1)
3.
n2
4.
(n2 + 8)
(n + 1)
5.
(nlogn + n2)
(n3 + 2)
6.
(n! + 2n)
(n3 + log(n2 + 1))
n
2
+nn
Using the definition of Big-O, prove the following:
7.
Given that f1(n) = O(g1(n) ) and f2(n) = O(g2(n) ). Prove that f1(n) f2(n)
is O(g1(n) g2(n) ).
2
CSC224/226 –Test 3 Review – Big-O & Binary Relations
Solutions
1.
nlog(n2 + 1) + n2 log n
nlogn2 + n2 logn = 2nlogn + n2 logn = nlogn + n2 logn ⇒ O(n2 logn)
2.
(nlogn + 1)2 + (logn + 1) (n2 + 1)
[(nlogn)2 + 2nlogn + 1] + [n2 logn + logn + n2 + 1] =
(nlogn)2 + nlogn + n2 logn + logn + n2 ⇒ O((nlogn)2 )
3.
n
2
n2 + n n
n
⇒ O(n2 )
4.
(n2 + 8)
(n + 1)
n2
n = n ⇒ O(n)
5.
(nlogn + n2)
(n3 + 2)
1
(nlogn + n2) n2 1
= 3 = n = O(n ) ⇒ O(n-1 )
3
n
n
6.
(n! + 2n)
(n3 + log(n2 + 1))
(n! + 2n)
(n! + 2n)
(n! + 2n)
n!
=
=
⇒ O( 3 )
3
3
3
2
n
(n + logn ) (n + 2log n) (n + logn)
3
CSC224/226 –Test 3 Review – Big-O & Binary Relations
7.
Given that f1(n) = O(g1(n) ) and f2(n) = O(g2(n) ).
Prove that
f1(n) f2(n) is O(g1(n) g2(n) ).
From the givens, we know the following:
f1(n) ≤ C1 g1(n) for n ≥ n1 and
f2(n) ≤ C2 g2(n) for n ≥ n2
Now we can multiply the two:
f1(n) f2(n) ≤ C1 C2 g1(n) g2(n) for n ≥ max of n1 and n2
With C = C1 C2 and n0
= max
of n1 and n2 , the previous line meets the
definition of Big-O.
All of this proves that f1(n) f2(n) is O(g1(n) g2(n) )
4
Download