taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.2.11.1-6

Exercise 1.2.11.1-6

not stated yet in Lean solution written

RatingM20
MarkersM (mathematical)
KindInformal: the exercise has no formal statement, so Lean does not state it from the written solution
SectionSection 1.2.11.1 of Volume 1. Companion chapter: The O-notation

The task

Find the fault in the argument that ∑k=1nkn=∑k=1nO(n)=O(n2)\sum_{k=1}^nkn=\sum_{k=1}^nO(n)=O(n^2) because each knkn is O(n)O(n).

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Compute the sum exactly and compare with n2n^2.

Hint 2

Ask how many OO symbols the middle expression holds, and whether one constant serves for all.

Solution

Show the solution

The sum is n⋅n(n+1)2=n3+n22n\cdot\frac{n(n+1)}2=\frac{n^3+n^2}2, which grows like n3n^3 and is not O(n2)O(n^2). So the conclusion is false.

The fault is in the first step. For each fixed kk the statement kn=O(n)kn=O(n) is true, with the constant M=kM=k. But the sum has nn terms, and the number of terms grows with nn. The nn symbols O(n)O(n) are replaced by one symbol with one constant MM, and no single MM works: the term knkn needs M≥kM\ge k, and kk runs up to nn. A bound O(f(n))O(f(n)) is a statement about a fixed number of terms, whose constants are fixed before nn is chosen.

The step ∑k=1nO(n)=O(n2)\sum_{k=1}^nO(n)=O(n^2) is correct if the same MM bounds every term, but here no such MM exists. The true bound is kn≤n2kn\le n^2 for each term, so the sum is O(n3)O(n^3).

For n=10n=10 the sum is 550550 and n2=100n^2=100, and for n=100n=100 it is 505 000505\,000 against 10 00010\,000. The ratio grows without bound.

Remarks

This is why Eq. (9) and (7) are stated for a fixed number of symbols. Sums with a variable number of terms need an explicit bound on the terms, as in Section 1.2.11.2.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.