Read [Gray], Chapters 2 and 3.
Consider the "Checkpoint" questions as part
of your reading assignment: answer them but don't turn in your
answers. This assignment is very unusual because it
has a lot of "busy work," but these
exercises are designed to give you the practice you
need at working with sets, functions, logs, and
asymptotic complexity. No whining.
Submit answers to the following problems, in a nicely typeset
pdf file:
- Write 2{a, b, c} in a form in which all elements are listed.
- How many partitions are there of {x | x ∈ N ∧ 1 ≤ x ∧ x ≤ 10}?
- Let A be a set and m and n be positive integers.
Would you say that Am+n = Am × An?
Give arguments for or against accepting this equality as fact.
Hint: you may want to consider the sets
A × A2
and A2 × A.
- Express, in lambda notation, the function which when passed
two functions f and g, returns the composition of f and g.
(Don't use the predefined "o" symbol for composition. Actually
define the meaning of composition in your answer.
- Consider the function
λx. 4x-3x2.
Call this function f.
- What is f0(0.01)?
- What is f1(0.01)?
- What is f2(0.01)?
- What is f5(0.01)?
- What is f30(0.01)?
- What is f50(0.01), according to Java?
- What is f50(0.01), according to your handheld calculator?
- Explain why we can never write out the value of f75(0.01)
in 10 point Times New Roman on printer paper that is produced on
Earth.
- Do you think it will possible in our lifetime whether we will
ever know the first digit of the decimal expansion of
f100(0.01). Why or why not?
- What is the time complexity of this code fragment?
(Use Θ-notation)
int x = 1;
for (int i = 0; i < n; i++) {
for (int j = 1; j <= x; j++) {
System.out.println("*");
}
x = x + x;
}
- What is the time complexity of this code fragment?
(Use Θ-notation)
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; i *= 2) {
System.out.println("*");
}
}
- What is the time complexity of this code fragment?
(Use Θ-notation)
for (int i = 1; i * i <= n; i++) {
for (int j = 1; j <= n; j += j) {
System.out.println("*");
}
}
- What is the time complexity of this code fragment?
(Use Θ-notation)
for (int i = 1; i <= n; i *= 2)
for (int j = 1; j <= i; j++)
System.out.println("*");
}
}
- What is the time complexity of this code fragment?
(Use Θ-notation)
for (int i = 1; i <= n * n; i++) {
for (int j = 1; j <= n; j *= 2) {
System.out.println("*");
}
}
- What is the time complexity of this code fragment?
(Use Θ-notation)
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j *= 2) {
System.out.println("*");
}
}
- What is the time complexity of this code fragment?
(Use Θ-notation)
for (int i = n; n >= 1; n /= 4) {
for (int j = 0; j < i; j++) {
System.out.println("*");
}
}
- Give both the best-case and worst-case time complexities
of this code fragment. (Use Θ-notation)
// Assume some global variable t is defined out here
for (int i = n; n >= 1; n /= 2) {
if (new Date().getTime() > t) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
}
}
- Give both the best-case and worst-case time complexities
of this function. (Use Θ-notation)
public static long power(int x, int n) {
return n == 0 ? 1
: n % 2 == 0 ? power(x * x, n / 2)
: x * power(x * x, n / 2)
}
- What is the time complexity (in
Θ-notation) of a procedure to
print out the exact value of 2n, where n is
a nonnegative integer? The procedure described is supposed to print
a result no matter how large the result may be.
- An algorithm with time complexity T(n) = n3 can process a
100-element list on our PC in 10 seconds.
- How long would it take to process a 200-element list?
- If we ran the algorithm on a machine that was 10 times
faster than our PC, how large of a list could we process in 30 seconds?
- How much faster than our PC would a computer have to be in order
to process a 1000000000-element list in a time span of 1 hour?
- An algorithm with complexity function
T(n) = n log n processes a 64-element list in
three minutes and 12 seconds on our PC.
- How long does it take to process a 128-element list?
- How large of a list could a computer that is 8 times faster
than our PC process in 10 seconds?
- How much faster would a computer have to be than our
PC to process a list of size 10 in a second?
- An algorithm of with time complexity function T, where
T(n) = 2n log n, can process a 32 element list in 2 minutes
and 40 seconds on our PC.
- How long would it take to process a 64 element list?
- If we ran the algorithm on a machine that was 4 times
faster than our PC, how large of a list could we process
in 16 seconds?
- We have seen that there is little
hope of solving problems of size 100 or so with algorithms of
complexity Θ(2n) even when billions of
operations can be carried out per second. But what about algorithms
of complexity Θ(1.1n)? How do these
algorithms compete with quadratic algorithms? In particular, if a
billion operations can be performed in one second, up to what
problem size will the Θ(1.1n) be faster
than a Θ(n2) algorithm?
- Rank each of the following functions by growth rate:
λn. n,
λn. n2,
λn. n1.5,
λn. sqrt(n),
λn. n log n,
λn. n log log n,
λn. n2 log n,
λn. n log n2,
λn. n (log n)2,
λn. 2,
λn. n3,
λn. 2/n,
λn. 2 log n,
λn. 2n,
λn. 2log n,
λn. 2n*n,
λn. 2n/2,
λn. n!,
λn. nn,
λn. (log n)n,
λn. log nn,
λn. log(sqrt(n)),
Compose the solutions to the project using the LaTeX
document preparation system, whether you want to or not.
Create a pdf from your document source, print it out,
and hand it in by the due date. It is not necessary to
email your solutions to this assignment.
Keep the LaTex source of your work around. If you
have not yet set up a CVS or SVN repository of your
work don't worry, because it will be required for
next assignment. At that point you can backfill
your repository with your work from this and the previous
assignment.
If you are already building up a repository, add to it
as follows:
homework
cmsi281
src
main
docs
hw3.tex
<diagram source files>, if any
<images>, if any