Appendix A

Exercise A.1-1

Any function belonging to O(fk(i))O(f_k(i)) is upper bounded by fk(i)f_k(i). Using the definition of the big O notation, gk(i)=O(fk(i)) g_k(i)=O(f_k(i)) implies gk(i)ckfk(i)g_k(i) \le c_kf_k(i) for some real constant ck>0c_k>0 and all ii^ki \ge \hat i_k. Define c=max{ck:1kn}c=max\{c_k:1\le k \le n\} and i0=max{i^k:1kn}i_0=max\{\hat i_k:1\le k \le n\}. For all ii0i\ge i_0 (assuming n0)n \ge 0)

k=1nO(fk(i))k=1nckfk(i)k=1ncfk(i)=ck=1nfk(i)k=1nO(fk(i))=O(k=1nfk(i))\begin{align*} \sum_{k=1}^n O(f_k(i)) &\le \sum_{k=1}^n c_kf_k(i) \\ &\le \sum_{k=1}^n cf_k(i) \\ &= c\sum_{k=1}^n f_k(i) \\ &\therefore \sum_{k=1}^n O(f_k(i))=O(\sum_{k=1}^n f_k(i)) \end{align*}

The asymptotic variable on both sides is ii whilst nn is essentially fixed. Regardless how we substitute those nn functions on the left, their sum is asymptotically bounded from above by a corresponding sum of upper bounds as ii \to \infty.

This equation is frequently employed in analysis of algorithms. Suppose our algorithm consists of n=3n=3 sections whose running times are O(ilgi)O(i\lg i), O(i2)O(i^2) and O(i)O(i). The total time is commensurate with their sum, which by our equation is O(ilgi+i2+i)=O(i2)O(i\lg i+i^2+i)=O(i^2), so our algorithm is quadratic in ii.

Exercise A.1-2

k=1n(2k1)=2k=1nkk=1n1(by the linearity property)=2n(n+1)2n(by equation (A.1))=n2\begin{align*} \sum_{k=1}^n(2k-1)&= 2\sum_{k=1}^n k - \sum_{k=1}^n 1 && \text{(by the linearity property)} \\ &=\frac{2n(n+1)}{2}-n && \text{(by equation (A.1))} \\ &= n^2 \end{align*}

Exercise A.1-3

111,111,111=k=0810k=1091101=999,999,9999111,111,111= \sum_{k=0}^8 10^k=\frac{10^9-1}{10-1}=\frac{999,999,999}{9}

Exercise A.1-4

Notice that our infinite series is absolutely convergent, since it transforms into a decreasing geometric series with x=12x=\frac {1}{2}, if we use absolute values of summands. Consequently, we can rearrange the terms. Denote the original sum as S, thus

2S=2(112+14...)=2S3S=2    S=23\begin{align*} 2S &= 2-(1-\frac {1}{2}+\frac {1}{4}-...)=2-S \\ &\therefore 3S=2 \implies S=\frac {2}{3} \end{align*}

Another possibility is to substitute x=12x=-\frac{1}{2} in equation (A.7).

Exercise A.1-5

We will find the two bounds (lower and upper) separately. The upper bound is

k=1nkck=1nnc=nck=1n1=nc+1k=1nkc=O(nc+1)\begin{align*} \sum_{k=1}^n k^c &\le \sum_{k=1}^n n^c=n^c\sum_{k=1}^n 1=n^{c+1} \\ &\therefore \sum_{k=1}^n k^c=O(n^{c+1}) \qquad \checkmark \end{align*}

The lower bound demands more work, as we drop half of the terms and try to bound a partial sum.

k=1nkck=n/2nkck=n/2nn/2c=(nn/2+1)n/2c=(n/2+1)n/2cn/2c+1(n/2)c+1=(12)c+1nc+1k=1nkc=Ω(nc+1)\begin{align*} \sum_{k=1}^n k^c&\ge \sum_{k=\lceil{n/2}\rceil}^n k^c \\ &\ge\sum_{k=\lceil{n/2}\rceil}^n \lceil{n/2}\rceil^c \\ &= (n-\lceil{n/2}\rceil+1)\lceil{n/2}\rceil^c \\ &=(\lfloor{n/2}\rfloor+1)\lceil{n/2}\rceil^c \\ &\ge \lceil{n/2}\rceil^{c+1} \\ &\ge {(n/2)}^{c+1} \\ &={\left(\frac{1}{2}\right)}^{c+1}n^{c+1} \\ &\therefore \sum_{k=1}^n k^c=\Omega(n^{c+1})\qquad \checkmark \end{align*}

Theorem 3.1 implies that k=1nkc=Θ(nc+1)\sum_{k=1}^n k^c=\Theta(n^{c+1}).

You may also want to look at Faulhaber's formula. It generalizes the sum of integer powers.

Exercise A.1-6

Differentiating both sides of the infinite geometric series (A.11) gives

k=1nk2xk1=(1x)2+2x(1x)(1x)4=(1x)+2x(1x)3=1+x(1x)3k=1nk2xk=x(1+x)(1x)3(after multiplying both sides with x)\begin{align*} \sum_{k=1}^n k^2x^{k-1}&=\frac{(1-x)^2+2x(1-x)}{(1-x)^4}\\ &=\frac{(1-x)+2x}{(1-x)^3}\\ &=\frac {1+x}{(1-x)^3} \\ &\therefore \sum_{k=1}^n k^2x^k = \frac {x(1+x)}{(1-x)^3} && \text{(after multiplying both sides with } x \text{)} \end{align*}

Exercise A.1-7

The upper bound is

k=1nklgkk=1nnlgn=nnlgn=n3/2lg1/2nk=1nklgk=O(n3/2lg1/2n)\begin{align*} \sum_{k=1}^n \sqrt {k\lg k} &\le \sum_{k=1}^n \sqrt {n\lg n} =n\sqrt {n\lg n}= n^{3/2} {\lg^{1/2} n} \\ &\therefore \sum_{k=1}^n \sqrt {k\lg k}=O(n^{3/2} {\lg^{1/2} n}) \qquad \checkmark \end{align*}

The lower bound can be attained by splitting the summation as in Exercise A.1-5 assuming n4n \ge 4, so that lgn1(lgn)/2\lg n - 1 \ge (\lg n)/2.

k=1nklgkk=n/2nklgkk=n/2nn/2lgn/2=(nn/2+1)n/2lgn/2=(n/2+1)n/2lgn/2n/2n/2lgn/2(n/2)(n/2)lg(n/2)=(n/2)(n/2)(lgn1)(n/2)(n/2)(lgn)/2=(14)n3/2lg1/2nk=1nklgk=Ω(n3/2lg1/2n)\begin{align*} \sum_{k=1}^n \sqrt {k\lg k} &\ge \sum_{k=\lceil{n/2}\rceil}^n \sqrt {k\lg k} \\ &\ge \sum_{k=\lceil{n/2}\rceil}^n \sqrt {\lceil{n/2}\rceil \lg \lceil{n/2}\rceil} \\ &= (n-\lceil{n/2}\rceil+1) \sqrt {\lceil{n/2}\rceil \lg \lceil{n/2}\rceil} \\ &=(\lfloor{n/2}\rfloor+1) \sqrt {\lceil{n/2}\rceil \lg \lceil{n/2}\rceil} \\ &\ge \lceil{n/2}\rceil \sqrt {\lceil{n/2}\rceil \lg \lceil{n/2}\rceil} \\ &\ge (n/2) \sqrt {(n/2) \lg (n/2)} \\ &= (n/2) \sqrt {(n/2) (\lg n - 1)} \\ &\ge (n/2) \sqrt {(n/2) (\lg n)/2} \\ &=\left(\frac{1}{4}\right) n^{3/2} {\lg^{1/2} n} \\ &\therefore \sum_{k=1}^n \sqrt {k\lg k}=\Omega(n^{3/2} {\lg^{1/2} n})\qquad \checkmark \end{align*}

Theorem 3.1 implies that k=1nklgk=Θ(n3/2lg1/2n)\sum_{k=1}^n \sqrt {k\lg k}=\Theta(n^{3/2} {\lg^{1/2} n}).

Exercise A.1-8

Equations (A.8) and (A.9) are our starting points.

k=1n12k1+k=1n12k=k=12n1k=H2n=ln2n+O(1)=lnn+1+O(1)\sum_{k=1}^n \frac {1}{2k-1}+\sum_{k=1}^n \frac {1}{2k}=\sum_{k=1}^{2n} \frac {1}{k}=H_{2n}=\ln 2n + O(1)=\ln n +1+O(1) \qquad \checkmark

We will keep all constants and bundle them under single O(1) only in the last step for better visibility. Observe that aO(1)+bO(1)+c=O(1)aO(1)+bO(1)+c=O(1) for all real constants aa, bb and cc. Let us multiply the leftmost and rightmost expressions by 2.

2k=1n12k1+k=1n1k=2lnn+2+2O(1)2k=1n12k1+Hn=2lnn+2+2O(1)2k=1n12k1+lnn+O(1)=2lnn+2+2O(1)2k=1n12k1=lnn+2+2O(1)O(1)k=1n12k1=lnn+O(1)\begin{align*} 2\sum_{k=1}^n \frac {1}{2k-1}+\sum_{k=1}^n \frac {1}{k}&=2\ln n +2+2O(1) \\ 2\sum_{k=1}^n \frac {1}{2k-1}+H_n &=2\ln n +2+2O(1) \\ 2\sum_{k=1}^n \frac {1}{2k-1}+\ln n + O(1) &=2\ln n +2+2O(1) \\ 2\sum_{k=1}^n \frac {1}{2k-1} &=\ln n +2+2O(1)-O(1) \\ \sum_{k=1}^n \frac {1}{2k-1} &=\ln {\sqrt{n}} +O(1) \end{align*}

Exercise A.1-9

We have an infinite sum similar to the one in (A.11) with x=1/2x=1/2. The linearity property also applies to infinite convergent series, but we must prove that our series converges. We can easily accomplish this by using the direct comparison test. The infinite sum in (A.11) converges for the given xx, thus we can use it as a reference. For all k>0k>0 it is indeed true that 0k12k<k2k0 \le \frac {k-1}{2^k} < \frac {k}{2^k}, so our series converges.

First we will use the linearity property of summations and afterward apply (A.11) and (A.7).

k=0k12k=k=0k2kk=012k=1/2(11/2)2111/2=0\sum_{k=0}^{\infin} \frac {k-1}{2^k}=\sum_{k=0}^{\infin} \frac {k}{2^k}-\sum_{k=0}^{\infin} \frac {1}{2^k}=\frac{1/2}{(1-1/2)^2}-\frac{1}{1-1/2}=0

Exercise A.1-10

If x=0x=0, then the result is zero, so assume that x0x \neq 0. Let y=x2y=x^2, since x<1    y<1|x|<1 \implies y<1.

The story is similar to Exercise A.1-9, although we cannot use the same convergence test. The limit comparison test turns out to be appropriate. We will again use the sum in (A.11) as a reference (using y instead of x), since we know it converges. All terms in both sums are positive (recall that k1k\ge1), so we can calculate the limit.

limk(2k+1)ykkyk=limk2k+1k=2\lim_{k \to \infin} \frac {(2k+1)y^k}{ ky^k}=\lim_{k \to \infin} \frac {2k+1}{k}=2 \qquad \checkmark

According to the test our sum converges. We can now proceed exactly as in the previous exercise.

k=1(2k+1)yk=2k=1kyk+k=0yk1=2y(1y)2+11y1=y(3y)(1y)2\begin{align*} \sum_{k=1}^\infty (2k+1)y^k&=2\sum_{k=1}^\infty ky^k +\sum_{k=0}^\infty y^k-1 \\ &=\frac {2y}{(1-y)^2}+\frac {1}{1-y}-1 \\ &=\frac {y(3-y)}{(1-y)^2}\qquad \checkmark \end{align*}

We have tweaked the starting index for kk in the expansion, hence that extra -1. After reversing the initial substitution we get

k=1(2k+1)x2k=x2(3x2)(1x2)2\sum_{k=1}^\infty (2k+1)x^{2k}=\frac {x^2(3-x^2)}{(1-x^2)^2}

Exercise A.1-11

P=k=2n(11k2)=k=2nk21k2=k=2n(k1)(k+1)k2P=\prod_{k=2}^n (1-\frac {1}{k^2})=\prod_{k=2}^n \frac {k^2-1}{k^2}=\prod_{k=2}^n \frac {(k-1)(k+1)}{k^2} \qquad \checkmark

Observe that all terms of the product are positive. Therefore, we can convert a formula with a product to a formula with a summation by using the identity from the book.

lgP=k=2n(lg(k1)+lg(k+1)2lgk)=k=2n(lg(k1)lgk)telescopes+k=2n(lg(k+1)lgk)telescopes=lg1lgnlg2+lg(n+1)=lgn+12nk=2n(11k2)=n+12n\begin{align*} \lg P&=\sum_{k=2}^n(\lg (k-1)+\lg(k+1)-2\lg k) \\ &=\underbrace{\sum_{k=2}^n(\lg(k-1)-\lg k)}_{\text{telescopes}}+\underbrace{\sum_{k=2}^n(\lg(k+1)-\lg k)}_{\text{telescopes}} \\ &=\lg 1-\lg n-\lg2+\lg(n+1) \\ &=\lg \frac {n+1}{2n} \qquad \checkmark\\ &\therefore \prod_{k=2}^n (1-\frac {1}{k^2})=\frac {n+1}{2n} \end{align*}

Exercise A.2-1

f(k)=1k2f(k) =\frac{1}{k^2} is a monotonically decreasing function, so we can use integral approximation (A.19) to bound the summation.

k=1n1k2=1+k=2n1k21+1ndxx2=11x1n=21n<2\sum_{k=1}^n \frac{1}{k^2}=1+\sum_{k=2}^n \frac{1}{k^2}\le 1+\int_1^n \frac{dx}{x^2}=1-\frac{1}{x}\bigg\rvert_1^n=2-\frac{1}{n}<2

Exercise A.2-2

k=0lgnn2k<k=0lgn(n2k+1)(by inequality (3.2))k=0lgnn2k+lgn+1(by linearity property)<k=0n2k+lgn+1=n11/2+lgn+1(by equation (A.7))=2n+lgn+13n(for all n2k=0lgnn2k=O(n)\begin{align*} \sum_{k=0}^{\lfloor\lg n\rfloor}\left\lceil\frac{n}{2^k}\right\rceil &< \sum_{k=0}^{\lfloor\lg n\rfloor}\left(\frac{n}{2^k}+1\right) && \text{(by inequality (3.2))} \\ &\le \sum_{k=0}^{\lfloor\lg n\rfloor}\frac{n}{2^k} +\lg n+1 && \text{(by linearity property)}\\ &< \sum_{k=0}^\infty\frac{n}{2^k} +\lg n+1\\ &= \frac{n}{1-1/2}+\lg n+1 && \text{(by equation (A.7))} \\ &= 2n+\lg n+1 \\ &\le 3n && \text{(for all } n \ge 2 \text{) } \\ &\therefore \sum_{k=0}^{\lfloor\lg n\rfloor}\left\lceil\frac{n}{2^k}\right\rceil=O(n) \end{align*}

Exercise A.2-3

The idea is to split the range 1 to n into lgn\lfloor\lg n\rfloor pieces and lower-bound the contribution of each piece by 1/2. The pieces are the same as in the case of calculating the upper bound. The only difference is that the representative (pivot) of each piece is 1/2i+11/2^{i+1} instead of 1/2i1/2^i for i=0,1,...,lgn1i=0,1,...,\lfloor\lg n\rfloor-1. Furthermore, some pieces may be missing in the last segment (for i=lgni=\lfloor\lg n\rfloor), but this is OK for getting the lower bound.

k=1n1ki=0lgn1j=02i112i+ji=0lgn1j=02i112i+1=i=0lgn1(1/2)=lgn/2>(lgn1)/2k=1n1k=Ω(lgn)\begin{align*} \sum_{k=1}^n\frac{1}{k} &\ge \sum_{i=0}^{\lfloor\lg n\rfloor-1}\sum_{j=0}^{2^i-1}\frac{1}{2^i+j} \\ &\ge \sum_{i=0}^{\lfloor\lg n\rfloor-1}\sum_{j=0}^{2^i-1}\frac{1}{2^{i+1}} \\ &= \sum_{i=0}^{\lfloor\lg n\rfloor-1}(1/2) \\ &= \lfloor\lg n\rfloor/2 \\ &> (\lg n - 1)/2 \\ &\therefore \sum_{k=1}^n\frac{1}{k} = \Omega(\lg n) \end{align*}

Exercise A.2-4

f(k)=k3f(k)=k^3 is monotonically increasing, so we can use integral approximation (A.18) to bound the summation.

0nx3dx=n44k=1nk31n+1x3dx=(n+1)414k=1nk3=Θ(n4)\begin{align*} \int_0^nx^3\,dx = \frac{n^4}{4}&\le \sum_{k=1}^nk^3 \le \int_1^{n+1}x^3\,dx =\frac{(n+1)^4-1}{4} \\ &\therefore \sum_{k=1}^nk^3=\Theta(n^4) \end{align*}

Exercise A.2-5

We would have an improper integral, since f(k) is undefined for k=0k=0.

Problem A-1

a.

k=1nkr=Θ(nr+1)(see Exercise A.1-5)\begin{align*} \sum_{k=1}^n k^r = \Theta(n^{r+1}) && \text{(see Exercise A.1-5)} \end{align*}

b.

The upper bound is

k=1nlgskk=1nlgsn=nlgsnk=1nlgsk=O(nlgsn)\sum_{k=1}^n\lg^sk \le \sum_{k=1}^n\lg^sn = n\lg^sn \therefore \sum_{k=1}^n\lg^sk=O(n\lg^sn) \qquad \checkmark

The lower bound is

k=1nlgskk=n/2nlgskk=n/2nlgs(n/2)=(nn/2+1)lgs(n/2)=(n/2+1)lgs(n/2)n/2lgs(n/2)(n/2)lgs(n/2)=(n/2)lgsnn/2k=1nlgsk=Ω(nlgsn)\begin{align*} \sum_{k=1}^n\lg^sk &\ge \sum_{k=\lceil{n/2}\rceil}^n\lg^sk \\ &\ge \sum_{k=\lceil{n/2}\rceil}^n\lg^s(\lceil{n/2}\rceil) \\ &= (n-\lceil{n/2}\rceil+1)\lg^s(\lceil{n/2}\rceil) \\ &= (\lfloor{n/2}\rfloor+1)\lg^s(\lceil{n/2}\rceil) \\ &\ge \lceil{n/2}\rceil\lg^s(\lceil{n/2}\rceil) \\ &\ge (n/2)\lg^s(n/2) \\ &= (n/2)\lg^s n-n/2 \\ &\therefore \sum_{k=1}^n\lg^sk=\Omega(n\lg^sn) \qquad \checkmark \end{align*}

Theorem 3.1 implies that k=1nlgsk=Θ(nlgsn)\sum_{k=1}^n\lg^sk=\Theta(n\lg^sn).

c.

The upper bound is

k=1nkrlgskk=1nnrlgsn=nr+1lgsnk=1nkrlgsk=O(nr+1lgsn)\sum_{k=1}^n k^r\lg^s k \le \sum_{k=1}^n n^r\lg^sn = n^{r+1}\lg^sn \therefore \sum_{k=1}^n k^r\lg^sk=O(n^{r+1}\lg^sn)\qquad \checkmark

The lower bound is

k=1nkrlgskk=n/2nkrlgskk=n/2nn/2rlgs(n/2)=(nn/2+1)n/2rlgs(n/2)=(n/2+1)n/2rlgs(n/2)n/2r+1lgs(n/2)(n/2)r+1lgs(n/2)=(n/2)r+1lgsn(n/2)r+1k=1nkrlgsk=Ω(nr+1lgsn)\begin{align*} \sum_{k=1}^n k^r\lg^sk &\ge \sum_{k=\lceil{n/2}\rceil}^n k^r\lg^sk \\ &\ge \sum_{k=\lceil{n/2}\rceil}^n {\lceil{n/2}\rceil}^r\lg^s(\lceil{n/2}\rceil) \\ &= (n-\lceil{n/2}\rceil+1) {\lceil{n/2}\rceil}^r\lg^s(\lceil{n/2}\rceil) \\ &= (\lfloor{n/2}\rfloor+1) {\lceil{n/2}\rceil}^r\lg^s(\lceil{n/2}\rceil) \\ &\ge {\lceil{n/2}\rceil}^{r+1}\lg^s(\lceil{n/2}\rceil) \\ &\ge (n/2)^{r+1}\lg^s(n/2) \\ &= (n/2)^{r+1}\lg^s n-(n/2)^{r+1} \\ &\therefore \sum_{k=1}^n k^r\lg^sk=\Omega(n^{r+1}\lg^sn)\qquad \checkmark \end{align*}

Theorem 3.1 implies that k=1nkrlgsk=Θ(nr+1lgsn)\sum_{k=1}^n k^r\lg^sk=\Theta(n^{r+1}\lg^sn).

Last updated