# 1. Asymptotic notation tricks

- To show equality, we will first show that every element of Theta(f(n)) is in O(f(n)) intersect Omega(f(n)), and then show that the reverse holds.
First observe that if g(n) is in O(f(n)) and Omega(f(n)), then there exist constants c, n

_{0}and c', n'_{0}such that g(n) <= c f(n) when n > n_{0}and g(n) >= c' f(n) when n > n'_{0}. So c' f(n) <= g(n) <= c f(n) for n > max(n_{0}, n'_{0}) and thus g(n) is in Theta(n).Now suppose g(n) is in Theta(n). Then there exist c

_{1}, c_{2}, n_{0}, such that c_{1}f(n) <= g(n) <= c_{2}f(n) for all n > n_{0}. But then c_{1}f(n) <= g(n) for all n > n_{0}---implying g(n) is in Omega(f(n))---and g(n) <= c_{2}f(n) for all n > n_{0}---implying it is in O(f(n)) as well. QED. Let p(n) be the polynomial. We will use the preceding result that p(n) is in Theta(n

^{k}) if and only if it is in both Omega(n^{k}) and O(n^{k}). Clearly p(n) is in Omega(n^{k}) because it exceeds a_{k}n^{k}for all n. To show that it is in O(n^{k}), argue by induction that p(n) - a_{k}n^{k}is in O(n^{k-1}), and then use the sum theorem from page 56 of LevitinBook to show p(n) in O(n^{k}).The only tricky part here is remembering that n

^{a}is in o(n^{b}) if and only if the limit as n goes to infinity of n^{a}/n^{b}is zero. But if a < b, then n^{a}/n^{b}= n^{a-b}= n^{-c}for a positive constant c, and so it goes to zero. (If you want to prove this formally, argue that for any epsilon, n^{-c}< epsilon for all n > epsilon^{-1/c}.)Now we want to show that ln

^{a}n / n^{b}goes to zero as long as b > 0. If a < 0, then the numerator goes to zero and we are done. If a = 0, then the fraction equals n^{-b}which again goes to zero. If a > 0, consider the ratio ln n / n^{b/a}; using L'HÃ´pital's rule (see Example 2 on page 57 of LevitinBook for an example of this) we have the limit as n goes to infinity of ln n / n^{b/a}equals the limit of (1/n)/((b/a) n^{b/a-1}) = n^{-b/a}/(b/a), which goes to zero in the limit since -b/a < 0.This is similar to the sum theorem from LevitinBook. Expanding the definition of O(r(n)) and O(s(n)) gives f(n) <= c

_{f}r(n) for n > n_{f}and g(n) <= c_{g}s(n) for n > n_{g}. So when n > max(n_{f}, n_{g}), f(n)g(n) <= c_{f}c_{g}r(n)s(n), which satisfies the criterion for membership in O(r(n)s(n)).

# 2. Sums

## 2.1. Exercise 2.3.1

All of these except the last can be done using the summation formulas on page 414 of LevitinBook.

- 1+3+5+7+ ... + 999 = (1+2+3+...+999) - (2+4+6+...+998) = (1+2+3+...+999) - 2(1+2+3+...+499) = 999*1000/2 - 2*499*500/2 = 999*500 - 499*500 = 500*500 = 250000. This uses the sum from 1 to n formula.
- 2+4+8+16+...+1024 = (2-1024*2)/(1-2) = 2046.
sum

_{i=3}^{n+1}1 = sum_{i=1}^{n+1}1 - sum_{i=1}^{2}1 = n+1-2 = n-1.sum

_{i=3}^{n+1}i = sum_{i=1}^{n+1}i - sum_{i=1}^{2}i = (n+1)(n+2)/2 - 3.sum

_{i=0}^{n-1}i(i+1) = sum_{i=0}^{n-1}i^{2}+ sum_{i=0}^{n-1}i = (n-1)n(2n-1)/6 + (n-1)n/2 = (n-1)n(n/3-1/6+1/2) = n(n-1)(n/3+1/3) = (n-1)n(n+1)/3.sum

_{j=1}^{n}3^{j+1}= 9 sum_{i=0}^{n-1}3^{i}= 9(3^{n}-1)/2sum

_{i=1}^{n}sum_{j=1}^{n}ij = (sum_{i=1}^{n}i)(sum_{j=1}^{n}j) = n^{2}(n+1)^{2}/4.

## 2.2. Exercise 2.3.4

It computes the sum as i goes from from 1 to n of i

^{2}.- The basic operation consists of squaring i and adding it to the running total.
- This operation is executed n times.
- This algorithm runs in Theta(n) time.
Use the formula sum

_{i=1}^{n}i^{2}= n(n+1)(2n+1)/6 to compute the solution directly in O(1) time.