QUIZ 1
(In class, Sep 29, 1998)
QUESTIONS
-
In Java, all classes are ultimately derived from
one single class. Name this class.
-
Two programs A and B have running times
TA(n))=100 n log n + 10000
TB(n))= n2 - 100
(a) Which is the faster algorithm?
(b) Qualify your answer to (a).
-
Order the following functions according to
their Theta-order (from smallest to largest):
- (a) sqrt(n),
- (b) log n,
- (c) n log n,
- (d) nlog23
ANSWERS
- The class is called the Object Class.
- (a) A is faster since O(n log n) is a asymptotically faster
than O(n2).
(b) But for small values of n, B may be faster.
In the example above, for instance, it is easy
to see that if n<100, then B is actually faster.
- ORDER: log n, sqrt(n), n log n, nlog23