CSPP 50102 Mathematics for Computer Science—Summer 2011
Homework 5 (assigned July 21, due July 26)
Reading: Rosen chapter 3, sections 3.1–3.3.
Written assignment : Solve the following "Do" exercises and
assigned problems. Only solutions to the assigned problems should be
turned in. Note: You are responsible for the material covered in
both "Do" exercises and assigned problems.
"Do" Exercises (not to be handed in):
-
The following are two useful rules for computing asymptotic bounds on algebraic combinations
of functions. Assume that all functions are nonnegative and real-valued.
-
If f1(n) = Θ(g1(n)) and
f2(n) = Θ(g2(n)), then
f1(n) + f2(n) =
Θ(max{g1(n), g2(n)}).
-
If f1(n) = Θ(g1(n)) and
f2(n) = Θ(g2(n)), then
f1(n) ⋅ f2(n) =
Θ(g1(n) ⋅ g2(n)).
Use the above rules to derive Θ-estimates for the following expressions.
-
(3n + 1)2
-
(6n + 4)(1 + log2n)
-
(n3 − 3n2 + 2)(log2n − 1)
+ (17 log2n + 19)(n3 − 2)
-
True or false? Prove your answer.
-
If f (n) = Θ(g(n)),
then 2f (n) = Θ(2g(n)).
-
If f (n) = Θ(g(n)),
then log2 f (n)
= Θ(log2 g(n)).
-
If f1(n) = Θ(g1(n)) and
f2(n) = Θ(g2(n)), then
f1(n) − f2(n) =
Θ(g1(n) − g2(n)).
-
For each of the following questions, answer yes or no and briefly explain your
answer.
-
If I prove that an algorithm takes O(n2) worst-case time, is
it possible that it takes O(n) on all inputs?
-
If I prove that an algorithm takes Θ(n2) worst-case time, is
it possible that it takes O(n) on some inputs?
-
If I prove that an algorithm takes Θ(n2) worst-case time, is
it possible that it takes O(n) on all inputs?
-
Given finite sets A and B, consider a function
f : A → B.
-
When f is injective, what is implied about the sizes of A and
B?
-
When f is surjective, what is implied about the sizes of A and
B?
-
Prove that if A and B are finite and
f : A → B and g : B → A
are injections, then |A| = |B| and f and g are
bijections.
Assigned problems (to be handed in):
-
Suppose you have algorithms with the five running times listed below. Assume these are the
exact number of operations performed as a function of the input size n. You have
a computer that can perform 1010 operations per second, and you need to compute
a result in at most 1 hour of computation. For each of the algorithms, what is the
largest input size n for which you would be able to get the result within 1 hour?
(2 points each)
-
n3
-
100n2
-
n log2n
-
2n
-
22n
-
True or false? Prove your answer using the definition of Big Oh. (5 points each)
-
22n = O(2n).
-
log2 3n
= O(log2 2n).
-
For each of the following pairs of functions f (n) and
g(n), give an appropriate positive constant c such that
|f (n)| ≤ c ⋅ |g(n)| for all
n ≥ 1.
(3 points each)
-
f (n) = 3n2 +
2n log2 n + 1,
g(n) = 2n2.
-
f (n) = n ⋅ √n + n2,
g(n) = n2.
-
f (n) = n2 − n + 1,
g(n) = n2/2.
-
For each of the following pairs of functions, either f (n) =
O(g(n)), f (n) = Ω(g(n)),
or f (n) = Θ(g(n)). Determine which relationship
is correct and prove your answer.
Note: log = log2 throughout. (5 points each)
-
f (n) = log n2;
g(n) = log n + 5.
-
f (n) = log2n, where
log2n =
(log n) × (log n);
g(n) = log n.
-
f (n) = n log n + n;
g(n) = log n.
-
f (n) = 10;
g(n) = log 10.
-
f (n) = 4n log n + n;
g(n) = (n2 − n)/2.
-
Find positive and nondecreasing functions f (n) and
g(n) defined for all positive integers such that neither
f (n) = O(g(n)) nor
g(n) = O(f (n)) holds. (10 points)
-
Find the flaw in the following proof that any algorithm has a run time that is
O(n). (10 points)
To prove: We must show that the time required for an input of size n is
at most a constant times n.
Proof. By induction on n.
Base case. Suppose that n = 1. If the algorithm takes c units of time
for an input of size 1, the algorithm takes at most
c ⋅ 1 units of time. Thus the assertion is true for n = 1.
Inductive step. Assume that the time required for an input of size n is
at most c′n and that the time for processing an additional item is
c′′. Then the total time required for an input of size n + 1 is
at most
-
c′n + c′′ ≤ cn + c =
c(n + 1).
The inductive step has been verified.
By induction, for input of size n, the time required is at most a
constant time n. Therefore, the run time is O(n).
Gerry Brady
Thursday July 21 13:10:19 CDT 2011