Question text in black, answers in blue.
Yes. Note that not all hand calculators can be trusted with very large numbers. But you only need to compute those numbers to enough accurracy to be sure which ones are bigger.
Neither, actually -- computer science logs are base 2. (Remember that in lecture I defined the log of a positive integer as the number of times you must cut it in half until you get 1.) More importantly, for big-O computations the base of the log doesn't matter. You may remember from high school that if a and b are any two positive numbers, the base-a log of x is equal to the base-b log of x, divided by the base-b log of a. If we have two functions and one is a constant times the other, they are big-O of each other and thus any function that is big-O of one is also big-O of the other. So O(log n) and O(ln n), for example, mean the same thing.
You are right -- they clearly meant to declare it as an
Integer
, so pretend that they did in your solution.
You may if you like, but I don't see any reason to. By any chance did you overlook the fact that you are supposed to return the odd numbers in reverse order, but return the even numbers in their original order? A Stack is useful for only one of these tasks, so you only need one Stack.
First, yes, f and g are the two functions that are
O(n2), meaning that they are each bounded above by a quadratic.
(By the way, note that in HTML here I can make superscripts and say
"O(n2)", but in email and in lecture I can't so I have to say
"O(n^2)" instead.)
Secondly, for a function to be bounded above by a quadratic means that there
is a quadratic polynomial that is always as big at it is. So any quadratic
is bounded above by a quadratic, namely itself. If f = n2 +
log n, f is not itself a quadratic because it is not a polynomial. But it is
always true that f(n) ≤ 2n2, because it is always true that
log n ≤ n2. But the function n3 is not
bounded above by any quadratic -- if you let a, b, and c be any numbers then
n2 will always be bigger than an2 + bn + c if n is large
enough.
In this problem you should assume that f and g are each bounded
above by quadratics, and use these assumptions to show that the function f+g
is also bounded above by some quadratic.
Last modified 25 September 2011