Homework #1

advertisement
Data Structures and Algorithms I
Spring 2010
Homework #1
(1) Order the following functions by growth rate (i.e., according to big-Oh complexity):
N2+7N-50, N3, N*log(N), 7N2*log(N), N2, 7N2-100N-90, N2log50(N),
N0.5+10, 10N*log(N10)+1, N1.5, 1.2N, 10N3-99N2-1000N-25, N25+N*log(N)
Be sure to indicate which functions grow at the same rate.
(2) State whether each of the following statements is true or false. Explain your answers!
(Note: as always in math, if the statement is not always true, it is considered false.)
(a) If the running time of an algorithm is O(2N), it is not feasible to apply the algorithm to large
data sets.
(b) If the running time of an algorithm is Ω(2N), it is not feasible to apply the algorithm to large
data sets.
(c) If T1(N) = O(N) and T2(N) = O(N2), then T1(N) + T2(N) = O(N2).
(d) If T1(N) = O(f(N)), and T2(N) = O(f(N)) then T1(N) / T2(N) = O(1).
(e) If T(N) = Θ(N2), then T(N) = O(N4).
(f) If T(N) = 10N3-6N2-6N+15, then T(N) = Ω(N3)
(3) Exercise 2.11 from the book (I am rewording the question slightly):
Assume that some implementation of an algorithm requires 0.5 ms for input size 100.
Approximately how long is required for input size 500 if the algorithm is:
(a) Linear
(b) Θ(NlogN)
(c) Quadratic
(d) Cubic
Assume that the low-order terms (i.e., the overhead of the program) are not significant. For part
(b) you cannot answer precisely, but describe the answer.
(4) Consider the following pseudo-code for a function that takes, as input, a parameter N:
Function F1(N)
Loop i from 1
Loop j from
F2(j)
Loop k from
if (F3(i)
F4(k)
else
F5(k)
to N
i to N2
i to N
> 10)
For each of the following assumptions, analyze the worst-case running time of F1 using Big-Oh
notation, Big-Omega notation, and Big-Theta notation, if possible. Express the tightest possible
answers. Explain your answers!
Note: In class, we went over rules related to Big-Oh notation. You will have to infer similar
rules for the other notations.
(a) Assume that the running time of F2(N) is O(N4), the running time F3(N) is O(N3), the
running time of F4(N) is O(N2), and the running time of F5(N) is O(N).
(b) Assume that the running time of F2(N) is O(N), the running time F3(N) is O(N), the running
time of F4(N) is O(N2), and the running time of F5(N) is O(N3).
(c) Assume that the running time of F2(N) is Ω(N), the running time F3(N) is Ω(N), the running
time of F4(N) is Ω(N2), and the running time of F5(N) is Ω(N3).
(d) Assume that the running time of F2(N) is Θ(N), the running time F3(N) is Θ(N), the running
time of F4(N) is Θ(N2), and the running time of F5(N) is Θ(N3).
Download