# Q&A for Homework #1, due Monday 26 September

Question text in black, answers in blue.

• Question H1.1, posted 25 September: In Exercise 2.2 of L&C, am I supposed to just plug in those two values for those two functions, and compare the results?

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.

• Question H1.2, posted 25 September: When we say "log", do we mean natural log or log base 10?

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.

• Question H1.3, posted 25 September: I think there's a mistake in L&C's Exercise 2.5 -- they use the variable Z without declaring it.

You are right -- they clearly meant to declare it as an `Integer`, so pretend that they did in your solution.

• Question H1.4, posted 25 September: May I use two Stack objects in my solution to your Question 6?

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.

• Question H1.5, posted 25 September: I am incredibly confused about Question #4. Do f and g refer to the O(n2)'s? And what does it mean to be "bounded above by a quadratic"?

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