Skip to main content

Exercises — Module 02 (Mathematical Preliminaries, §1.2)

Self-contained problems on this module's toolkit — induction, sums by the perturbation method, binomial coefficients, Fibonacci numbers, and the analysis of Algorithm M. You can work every one without the book: each states the problem in full, gives a hint to peek at when stuck, and a worked answer sketch to check against. Every numeric value below is reproduced by a few lines at a REPL (or the exact-arithmetic code you write in the lab).

Ratings follow Knuth's scale (00–50; M = needs mathematics, ▶ = especially instructive). Where a problem mirrors a TAOCP exercise, its number is noted for readers who own Volume 1.

Tracking​

#TopicRatingStatus
1Induction warm-up: sum of cubes (Nicomachus)10⬜
2▶ Perturbation method: derive ∑kk xk\sum_{k} k\,x^k20⬜
3A binomial identity by Pascal's rule: ∑k(nk)=2n\sum_k \binom{n}{k} = 2^n17⬜
4▶ k!k! divides any product of kk consecutive integers25⬜
5A Fibonacci identity by induction: Cassini20⬜
6The variance of AA in Algorithm M27⬜

Problems​

1. Induction warm-up: sum of cubes (Nicomachus) (rating 10 · cf. 1.2.1–1)​

Problem. Prove by mathematical induction that

∑k=1nk3=(n(n+1)2)2for all n≥1.\sum_{k=1}^{n} k^3 = \left(\frac{n(n+1)}{2}\right)^2 \quad\text{for all } n \ge 1.

That is: the sum of the first nn cubes equals the square of the nn-th triangular number.

Hint. Basis n=1n = 1 is immediate. For the step, add (n+1)3(n+1)^3 to the assumed formula and factor the result into ((n+1)(n+2)/2)2\big((n+1)(n+2)/2\big)^2 — the lesson states exactly this factoring move.

Answer sketch. Basis: 13=1=(1⋅2/2)21^3 = 1 = (1 \cdot 2 / 2)^2. Induction: assume ∑k=1nk3=(n(n+1)/2)2\sum_{k=1}^{n} k^3 = \big(n(n+1)/2\big)^2. Then

∑k=1n+1k3=(n(n+1)2)2+(n+1)3=(n+1)2(n24+(n+1))=(n+1)2⋅n2+4n+44=((n+1)(n+2)2)2,\sum_{k=1}^{n+1} k^3 = \left(\frac{n(n+1)}{2}\right)^2 + (n+1)^3 = (n+1)^2\left(\frac{n^2}{4} + (n+1)\right) = (n+1)^2 \cdot \frac{n^2 + 4n + 4}{4} = \left(\frac{(n+1)(n+2)}{2}\right)^2,

which is the formula at n+1n+1. ■\blacksquare (Numerical check: 1+8+27+64=100=(4⋅5/2)2=1021+8+27+64 = 100 = (4\cdot 5/2)^2 = 10^2.)

2. ▶ Perturbation method: derive ∑kk xk\sum_{k} k\,x^k (rating 20 · cf. 1.2.3–16)​

Problem. Using the perturbation method (compute Sn+1S_{n+1} two ways, by splitting off the last term and the first term, then solve), derive a closed form for S=∑k=0nk xkS = \sum_{k=0}^{n} k\,x^k. Specialize to x=2x = 2 and confirm the result ∑k=0nk 2k=(n−1) 2n+1+2\sum_{k=0}^{n} k\,2^k = (n-1)\,2^{n+1} + 2.

Hint. You will need the geometric sum ∑k=0nxk=xn+1−1x−1\sum_{k=0}^{n} x^k = \dfrac{x^{n+1}-1}{x-1} (derived in the lesson by the same trick) as an input, because splitting off the first term leaves a ∑xk\sum x^k behind.

Answer sketch. Let S=∑k=0nk xkS = \sum_{k=0}^{n} k\,x^k. Split Sn+1=∑k=0n+1kxkS_{n+1} = \sum_{k=0}^{n+1} k x^k two ways. Last term: Sn+1=S+(n+1)xn+1S_{n+1} = S + (n+1)x^{n+1}. First term (reindex k→k+1k \to k+1): Sn+1=∑k=0n(k+1)xk+1=x∑k=0nkxk+x∑k=0nxk=xS+x GS_{n+1} = \sum_{k=0}^{n}(k+1)x^{k+1} = x\sum_{k=0}^{n} k x^k + x\sum_{k=0}^{n} x^k = xS + x\,G, where G=xn+1−1x−1G = \dfrac{x^{n+1}-1}{x-1}. Equating, S+(n+1)xn+1=xS+xGS + (n+1)x^{n+1} = xS + xG, so

S(1−x)=xG−(n+1)xn+1=x(xn+1−1)x−1−(n+1)xn+1,S=x−(n+1)xn+1+n xn+2(1−x)2(x≠1).S(1-x) = xG - (n+1)x^{n+1} = \frac{x(x^{n+1}-1)}{x-1} - (n+1)x^{n+1}, \qquad S = \frac{x - (n+1)x^{n+1} + n\,x^{n+2}}{(1-x)^2}\quad (x \ne 1).

At x=2x = 2: denominator (1−2)2=1(1-2)^2 = 1, numerator 2−(n+1)2n+1+n 2n+2=2+2n+1(2n−(n+1))=(n−1)2n+1+22 - (n+1)2^{n+1} + n\,2^{n+2} = 2 + 2^{n+1}\big(2n - (n+1)\big) = (n-1)2^{n+1} + 2. So ∑k=0nk 2k=(n−1)2n+1+2\sum_{k=0}^{n} k\,2^k = (n-1)2^{n+1} + 2. (Checks: n=2n=2 gives 1⋅8+2=10=0+2+81\cdot 8 + 2 = 10 = 0 + 2 + 8; n=4n=4 gives 3⋅32+2=983\cdot 32 + 2 = 98.)

3. A binomial identity by Pascal's rule: ∑k(nk)=2n\sum_k \binom{n}{k} = 2^n (rating 17 · cf. 1.2.6)​

Problem. Prove the row-sum identity ∑k=0n(nk)=2n\sum_{k=0}^{n} \binom{n}{k} = 2^n by induction on nn, using Pascal's rule (nk)=(n−1k−1)+(n−1k)\binom{n}{k} = \binom{n-1}{k-1} + \binom{n-1}{k} (rather than the binomial theorem).

Hint. Let Rn=∑k(nk)R_n = \sum_k \binom{n}{k}. Substitute Pascal's rule into RnR_n and watch each row-(n−1)(n-1) term get counted twice.

Answer sketch. Basis: R0=(00)=1=20R_0 = \binom{0}{0} = 1 = 2^0. Induction: assume Rn−1=2n−1R_{n-1} = 2^{n-1}. Using Pascal's rule on every interior term (with the boundary convention (n−1−1)=(n−1n)=0\binom{n-1}{-1} = \binom{n-1}{n} = 0),

Rn=∑k=0n(nk)=∑k=0n((n−1k−1)+(n−1k))=∑k(n−1k−1)+∑k(n−1k)=Rn−1+Rn−1=2Rn−1.R_n = \sum_{k=0}^{n}\binom{n}{k} = \sum_{k=0}^{n}\left(\binom{n-1}{k-1} + \binom{n-1}{k}\right) = \sum_{k}\binom{n-1}{k-1} + \sum_{k}\binom{n-1}{k} = R_{n-1} + R_{n-1} = 2R_{n-1}.

Each row-(n−1)(n-1) entry appears once in each of the two shifted sums, so the total doubles. Hence Rn=2⋅2n−1=2nR_n = 2 \cdot 2^{n-1} = 2^n. ■\blacksquare (This is the same addition-formula engine that proves every (nk)\binom{n}{k} is an integer — the recurrence Rn=2Rn−1R_n = 2R_{n-1} is Pascal's rule summed across a row.)

4. ▶ k!k! divides any product of kk consecutive integers (rating 25 · cf. 1.2.6–10)​

Problem. Show directly — without invoking Pascal's rule or an induction on the triangle — that k!k! divides the product of any kk consecutive integers, i.e. that

(nk)=n(n−1)⋯(n−k+1)k!\binom{n}{k} = \frac{n(n-1)\cdots(n-k+1)}{k!}

is always an integer for integers n≥k≥0n \ge k \ge 0.

Hint. The lesson's combinatorial definition of (nk)\binom{n}{k} is the key: it counts something, and a count is a non-negative integer regardless of the formula you compute it with.

Answer sketch. By the lesson's definition, (nk)\binom{n}{k} is the number of kk-element subsets of an nn-element set — an integer, because it counts objects. But that same quantity equals n(n−1)⋯(n−k+1)k!\dfrac{n(n-1)\cdots(n-k+1)}{k!}: form an ordered selection of kk distinct elements (n(n−1)⋯(n−k+1)n(n-1)\cdots(n-k+1) ways), then note each kk-subset arises from exactly k!k! orderings, so dividing by k!k! counts unordered subsets. Since the left side (a count) is an integer, k!k! must divide the numerator n(n−1)⋯(n−k+1)n(n-1)\cdots(n-k+1) — the product of kk consecutive integers. ■\blacksquare This is double counting: the integrality is free once you see the quotient is really a count. (An alternative prime-power argument — show each prime pp divides the numerator at least as often as the denominator — also works but is longer; the combinatorial one is the instructive route.)

5. A Fibonacci identity by induction: Cassini (rating 20 · cf. 1.2.8, Eq. 8)​

Problem. With Knuth's indexing F0=0F_0 = 0, F1=1F_1 = 1, Fn+1=Fn+Fn−1F_{n+1} = F_n + F_{n-1}, prove Cassini's identity

Fn−1 Fn+1−Fn2=(−1)nfor all n≥1F_{n-1}\,F_{n+1} - F_n^2 = (-1)^n \quad\text{for all } n \ge 1

by induction on nn.

Hint. Basis n=1n = 1: F0F2−F12=0⋅1−1=−1=(−1)1F_0 F_2 - F_1^2 = 0 \cdot 1 - 1 = -1 = (-1)^1. For the step, express Fn+2=Fn+1+FnF_{n+2} = F_{n+1} + F_n and reduce FnFn+2−Fn+12F_n F_{n+2} - F_{n+1}^2 to the previous case; the sign flips each time.

Answer sketch. Basis (n=1n=1): F0F2−F12=0⋅1−12=−1=(−1)1F_0 F_2 - F_1^2 = 0\cdot 1 - 1^2 = -1 = (-1)^1. ✓ Induction: assume Fn−1Fn+1−Fn2=(−1)nF_{n-1}F_{n+1} - F_n^2 = (-1)^n. Then, using Fn+2=Fn+1+FnF_{n+2} = F_{n+1} + F_n,

FnFn+2−Fn+12=Fn(Fn+1+Fn)−Fn+12=Fn+1(Fn−Fn+1)+Fn2=−Fn+1Fn−1+Fn2F_n F_{n+2} - F_{n+1}^2 = F_n(F_{n+1}+F_n) - F_{n+1}^2 = F_{n+1}(F_n - F_{n+1}) + F_n^2 = -F_{n+1}F_{n-1} + F_n^2

(since Fn−Fn+1=−Fn−1F_n - F_{n+1} = -F_{n-1}) =−(Fn−1Fn+1−Fn2)=−(−1)n=(−1)n+1= -\big(F_{n-1}F_{n+1} - F_n^2\big) = -(-1)^n = (-1)^{n+1}, which is Cassini at n+1n+1. ■\blacksquare (Spot check: n=6n = 6, F5F7−F62=5⋅13−82=65−64=1=(−1)6F_5 F_7 - F_6^2 = 5\cdot 13 - 8^2 = 65 - 64 = 1 = (-1)^6.) The sign alternation is the algebra behind the classic 8×8→5×138\times 8 \to 5\times 13 dissection "paradox" mentioned in the lesson.

6. The variance of AA in Algorithm M (rating 27 · cf. 1.2.10)​

Problem. Algorithm M scans X[1..n]X[1..n] right-to-left and AA counts how often the running maximum changes (executions of step M4). Its generating function is

Gn(z)=z+12⋅z+23⋯z+n−1n.G_n(z) = \frac{z+1}{2}\cdot\frac{z+2}{3}\cdots\frac{z+n-1}{n}.

Show that Var⁡(A)=Hn−Hn(2)\operatorname{Var}(A) = H_n - H_n^{(2)}, where Hn=∑k=1n1/kH_n = \sum_{k=1}^{n} 1/k and Hn(2)=∑k=1n1/k2H_n^{(2)} = \sum_{k=1}^{n} 1/k^2, and verify it numerically for n=6n = 6 against the exact histogram of AA (counts 120,274,225,85,15,1120, 274, 225, 85, 15, 1 for A=0,1,…,5A = 0, 1, \dots, 5).

Hint. Write A=∑k=1n−1IkA = \sum_{k=1}^{n-1} I_k as a sum of independent indicators, where Ik=1I_k = 1 with probability pk=1/(n−k+1)p_k = 1/(n-k+1) (the lesson proves position kk is a right-to-left maximum with this probability, and notes the indicators are independent). For independent indicators, variances add, and Var⁡(Ik)=pk(1−pk)\operatorname{Var}(I_k) = p_k(1 - p_k).

Answer sketch. Because the IkI_k are independent Bernoulli(pk)(p_k) with pk=1/(n−k+1)p_k = 1/(n-k+1), letting j=n−k+1j = n-k+1 range over 2,3,…,n2, 3, \dots, n,

Var⁡(A)=∑k=1n−1pk(1−pk)=∑j=2n1j(1−1j)=∑j=2n(1j−1j2)=(Hn−1)−(Hn(2)−1)=Hn−Hn(2).\operatorname{Var}(A) = \sum_{k=1}^{n-1} p_k(1-p_k) = \sum_{j=2}^{n}\frac{1}{j}\left(1 - \frac{1}{j}\right) = \sum_{j=2}^{n}\left(\frac{1}{j} - \frac{1}{j^2}\right) = (H_n - 1) - (H_n^{(2)} - 1) = H_n - H_n^{(2)}.

(Equivalently this drops out of Var⁡(A)=Gn′′(1)+Gn′(1)−Gn′(1)2\operatorname{Var}(A) = G_n''(1) + G_n'(1) - G_n'(1)^2 with Gn′(1)=E[A]=Hn−1G_n'(1) = E[A] = H_n - 1.) Numerical check, n=6n = 6: the exact histogram (120,274,225,85,15,1)/720(120, 274, 225, 85, 15, 1)/720 has mean E[A]=1044/720=1.45=H6−1E[A] = 1044/720 = 1.45 = H_6 - 1 and E[A2]=2204/720E[A^2] = 2204/720, giving Var⁡(A)=E[A2]−E[A]2≈0.95861\operatorname{Var}(A) = E[A^2] - E[A]^2 \approx 0.95861. And H6−H6(2)=4920−53693600≈2.45−1.49139=0.95861H_6 - H_6^{(2)} = \tfrac{49}{20} - \tfrac{5369}{3600} \approx 2.45 - 1.49139 = 0.95861. The two agree. ■\blacksquare (So the standard deviation is only about ln⁡n\sqrt{\ln n}: AA is tightly concentrated.)


Your solutions​

Use this space to log your own work — a restated problem, your approach, and how it compared with the sketch above.

Exercise N (rating RR)​

Approach. Answer / proof. Compared with the sketch: what you did differently, what you missed.