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 · 2.2.1-12

Exercise 2.2.1-12

not stated yet in Lean solution written

RatingHM34
MarkersHM (needs higher mathematics)
KindK4, find an estimate: give an asymptotic form or a bound from the written solution
SectionSection 2.2.1 of Volume 1

The task

Find the asymptotic values of ana_n (the stack count of Exercise 2.2.1-4) and of bnb_n (the deque count of Exercise 2.2.1-11).

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

For an=(2nn)/(n+1)a_n = \binom{2n}{n}/(n+1), use Stirling's formula.

Hint 2

For bnb_n, the generating function has a square root. Find its singularities and their size. The nearest one to the origin gives the growth.

Solution

Show the solution

Plan. Use Stirling's formula for ana_n. For bnb_n, find the dominant singularity of the generating function, write the function there as a square root times an analytic factor, and transfer the singular term to the coefficients.

The numbers ana_n. By Stirling's formula, (2nn)=4nπn(1+O(1/n))\binom{2n}{n} = \dfrac{4^n}{\sqrt{\pi n}}\bigl(1 + O(1/n)\bigr). Divide by n+1=n(1+1/n)n+1 = n(1 + 1/n): an=4nπ n3/2(1+O(n−1)).a_n = \frac{4^n}{\sqrt{\pi}\, n^{3/2}}\bigl(1 + O(n^{-1})\bigr).

The numbers bnb_n. The generating function is B(z)=12(3−z−1−6z+z2)B(z) = \frac12\bigl(3 - z - \sqrt{1 - 6z + z^2}\bigr). The polynomial 1−6z+z21 - 6z + z^2 has the roots ρ=3−22,ρ′=3+22=1/ρ,\rho = 3 - 2\sqrt2, \qquad \rho' = 3 + 2\sqrt2 = 1/\rho, and 1−6z+z2=(1−z/ρ)(1−z/ρ′)1 - 6z + z^2 = (1 - z/\rho)(1 - z/\rho'). Since ρ<ρ′\rho < \rho', the function BB is analytic in the whole plane except for the branch cuts that start at ρ\rho and ρ′\rho'. So ρ\rho is the only singularity on the circle ∣z∣=ρ|z| = \rho, and BB extends analytically to a slightly larger region with a notch at ρ\rho.

Near ρ\rho write B(z)=3−z2−12 h(z)1−z/ρ,h(z)=1−z/ρ′.B(z) = \frac{3 - z}{2} - \frac12\, h(z)\sqrt{1 - z/\rho}, \qquad h(z) = \sqrt{1 - z/\rho'}. The function hh is analytic at ρ\rho, with h(ρ)2=1−ρ/ρ′=1−ρ2=122−16.h(\rho)^2 = 1 - \rho/\rho' = 1 - \rho^2 = 12\sqrt2 - 16. The coefficient of wnw^n in 1−w\sqrt{1-w} is −12π n−3/2(1+O(1/n))-\dfrac{1}{2\sqrt\pi}\, n^{-3/2}\bigl(1 + O(1/n)\bigr). The transfer theorem of Flajolet and Odlyzko moves this estimate to BB, with the factor 12h(ρ)\frac12 h(\rho) and the scale ρ−n\rho^{-n}: bn=h(ρ)4π ρ−nn−3/2(1+O(n−1)).b_n = \frac{h(\rho)}{4\sqrt\pi}\,\rho^{-n} n^{-3/2}\bigl(1 + O(n^{-1})\bigr).

Now simplify the constant. Since h(ρ)2/16=(32−4)/4h(\rho)^2/16 = (3\sqrt2 - 4)/4, and ((2−1)/23/4)2=(3−22)/(22)=(32−4)/4\bigl((\sqrt2 - 1)/2^{3/4}\bigr)^2 = (3 - 2\sqrt2)/(2\sqrt2) = (3\sqrt2 - 4)/4, we have h(ρ)/4=(2−1)/23/4h(\rho)/4 = (\sqrt2-1)/2^{3/4}. Also ρ−1=3+22=(1+2)2\rho^{-1} = 3 + 2\sqrt2 = (1 + \sqrt2)^2. Hence bn=(2−1)(3+22)n23/4π  n3/2(1+O(n−1)).b_n = \frac{(\sqrt2 - 1)(3 + 2\sqrt2)^n}{2^{3/4}\sqrt\pi\; n^{3/2}}\bigl(1 + O(n^{-1})\bigr).

The growth rates are 44 for ana_n and 3+22≈5.833 + 2\sqrt2 \approx 5.83 for bnb_n.

Check

I computed the exact ratio of ana_n and bnb_n to their formulas. For ana_n the ratio is 0.89780.8978 at n=10n = 10 and 0.98130.9813 at n=59n = 59. For bnb_n it is 1.03681.0368 at n=10n = 10, 1.00711.0071 at n=50n = 50, and 1.00601.0060 at n=59n = 59. The distance from 11 falls like 1/n1/n in both cases. The two forms of the constant agree: (2−1)/23/4=0.246293(\sqrt2-1)/2^{3/4} = 0.246293 and 122−16/4=0.246293\sqrt{12\sqrt2 - 16}/4 = 0.246293.

Remarks

A deque with restricted output thus gives about (5.83/4)n≈1.46n(5.83/4)^n \approx 1.46^n times as many permutations as a stack. The book's answer reaches the formula for bnb_n by a direct expansion of the coefficients, and the transfer from the singularity is another route to the same constant.

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.