1. f is Theta(n) means there exists constants c, C, and N such that
cn <= f(n) <= Cn for all n>=N.
g is O(n) means that there exists constants C', N' such that
g(n) <= C'n for all n>= N'.
Assume g(n) >= 0 for all n (needed for the left-hand inequality below.
I should have made that clear in the problem statement). We then have
that
cn <= f(n) + g(n) <= Cn + C'n for all n >= max{N,N'}.
So: select d = c and D = max{C,C'} (or D=C+C')
and M = max{N,N'} and we see that
dn <= f(n) + g(n) <= Dn for all n>=M.
Thus f(n) + g(n) is Theta(n).
2. Assume that when we break up a list of odd length n, we do it
floor{n/2} elements on the left and ceiling{n/2} on the right.
Then: make sure that at each stage, the largest value is on the right,
and the second largest value is on the left. Lots of ways to do
this. For example:
45678 01239
67 458 23 019
45 8 01 9
Solution: 6 7 4 5 8 2 3 0 1 9
1 2 3 4 5 6 14 8 9 10 11 12 13 14 15
1 2 6 3 4 5 14
1 2 6 3 5 4 14 8 9 10 14 11 12 13 15
8 10 9 14 11 13 12 15
Solution: 1 2 6 3 5 4 14 8 10 9 14 11 13 12 15
3. People did this correctly ;-)
4.1 Theta(n lg n) by the Master Theorem
4.2 Thata (n lg^2 n) by repeated substituition. Note: the Master theorem
does NOT apply.
4.3 Theta(n!)
4.4 Theta(n^2)
4.5 Theta(n^3) (by substition method)