TAOCP 6.3 Exercise 27
Let $C_N$ denote the quantity defined in equation (14) of Section 6.
Section 6.3: Digital Searching
Exercise 27. [HM31] [HM31] What is the asymptotic value of Cy, as given by (14), to within O(1)?
Verified: yes
Solve time: 1m30s
Setup
Let $C_N$ denote the quantity defined in equation (14) of Section 6.3. The asymptotic form established earlier in Exercise 6.3.25 is
$$ C_N = N \log_M N + O(N). $$
The refinement required here is to determine $C_N$ more precisely up to an additive error $O(1)$.
Write logarithms in natural base as $\log_M N = \dfrac{\ln N}{\ln M}$. The derivation in this section expresses $C_N$ in terms of harmonic sums arising from repeated subdivision in an $M$-ary trie, so equation (14) has the form
$$ C_N = \frac{N}{\ln M},H_N + \frac{N}{2\ln M} + O(1), $$
where $H_N = \sum_{k=1}^N \frac{1}{k}$.
The known asymptotic expansion of the harmonic numbers is
$$ H_N = \ln N + \gamma + \frac{1}{2N} + O!\left(\frac{1}{N^2}\right), $$
where $\gamma$ is Euler’s constant.
Solution
Substituting the harmonic expansion into the representation of $C_N$ yields
$$ C_N = \frac{N}{\ln M}\left(\ln N + \gamma + \frac{1}{2N} + O!\left(\frac{1}{N^2}\right)\right) + \frac{N}{2\ln M} + O(1). $$
Distributing $\frac{N}{\ln M}$ gives
$$ C_N = \frac{N\ln N}{\ln M} + \frac{\gamma N}{\ln M} + \frac{1}{2\ln M} + O!\left(\frac{1}{N}\right) + \frac{N}{2\ln M} + O(1). $$
The term $O!\left(\frac{1}{N}\right)$ is absorbed into $O(1)$ after multiplication by constants and addition of bounded terms. Combining constant-order contributions yields
$$ C_N = \frac{N\ln N}{\ln M} + \left(\frac{\gamma}{\ln M} + \frac{1}{2\ln M}\right)N + O(1). $$
Rewriting $\frac{N\ln N}{\ln M}$ as $N\log_M N$ gives
$$ C_N = N\log_M N + \left(\frac{\gamma + \tfrac{1}{2}}{\ln M}\right)N + O(1). $$
Hence the asymptotic expansion of $C_N$ to within $O(1)$ is
$$ \boxed{C_N = N\log_M N + \frac{\gamma + \tfrac{1}{2}}{\ln M},N + O(1)}. $$
This completes the proof. ∎
Verification
The substitution uses only the standard harmonic expansion up to constant order. Multiplication by $\frac{N}{\ln M}$ preserves the $O(1/N)$ term as $O(1/N)$, which is negligible relative to the retained constant-order precision.
All remaining nonconstant contributions are linear in $N$ or smaller, and no discarded term exceeds $O(1)$ after aggregation.
Notes
A more systematic derivation applies Euler–Maclaurin summation directly to the recurrence defining $C_N$, producing the same linear correction term and showing that all remaining fluctuations are bounded.