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-11

Exercise 2.2.1-11

not stated yet in Lean solution written

RatingM40
MarkersM (mathematical)
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 2.2.1 of Volume 1

The task

By Exercises 2.2.1-9 and 2.2.1-10, bnb_n is the number of admissible sequences with nn letters X. Find a closed form for the generating function ∑n≥0bnzn\sum_{n \ge 0} b_n z^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

Use the fact, found in the remarks of Exercise 2.2.1-10, that an X which empties the deque is the last letter. So the deque stays non-empty from the first letter to the last X.

Hint 2

Count each insert with weight 22 when the choice between S and Q is free, and with weight 11 when it is forced.

Solution

Show the solution

Plan. Turn the admissible sequences into weighted Dyck words. Split a Dyck word at its first return, as for the Catalan numbers. Solve a quadratic equation.

Write U for an insert (S or Q) and D for X. An admissible sequence with n≥1n \ge 1 starts with an insert. By rule 3 of Exercise 2.2.1-10 that insert is Q. After it, the deque is not empty until the last letter, which is X. So the sequence has the form U PP D, where PP is a Dyck word of length 2(n−1)2(n-1), that is, a word with the same number of U and D and no prefix with more D than U.

The number of ways to choose the letters from {\{S, Q}\} for a given word is a product over the inserts. The first insert is Q, one way. Any other insert comes with a non-empty deque, so rule 3 does not bind it. If it follows an X, rule 4 forces S, one way. If it follows another insert, both S and Q are free, two ways. So the weight of U PP D is 2m2^{m}, where mm is the number of factors UU in the word U PP.

Let uu(w)uu(w) count the factors UU of a word ww. Define F(z)=∑P2uu(P)z∣P∣,G(z)=∑P2uu(𝚄P)z∣P∣,F(z) = \sum_P 2^{uu(P)} z^{|P|}, \qquad G(z) = \sum_P 2^{uu(\mathtt{U}P)} z^{|P|}, where PP runs over all Dyck words and ∣P∣|P| is the number of U in PP. Then B(z)=∑n≥0bnzn=1+zG(z),B(z) = \sum_{n \ge 0} b_n z^n = 1 + zG(z), since bnb_n is the sum of 2uu(𝚄P)2^{uu(\mathtt{U}P)} over the Dyck words PP with n−1n - 1 letters U, for n≥1n \ge 1, and b0=1b_0 = 1.

Every non-empty Dyck word has one form P=𝚄 P1 𝙳 P2P = \mathtt{U}\,P_1\,\mathtt{D}\,P_2 with Dyck words P1P_1 and P2P_2. The letter D breaks every factor, so uu(P)=uu(𝚄P1)+uu(P2),uu(𝚄P)=1+uu(𝚄P1)+uu(P2).uu(P) = uu(\mathtt{U}P_1) + uu(P_2), \qquad uu(\mathtt{U}P) = 1 + uu(\mathtt{U}P_1) + uu(P_2). The 11 in the second formula is the factor made of the first two letters. These formulas give F=1+zGF,G=1+2zGF.F = 1 + zGF, \qquad G = 1 + 2zGF.

Put u=zGu = zG. The first equation is F=1/(1−u)F = 1/(1-u). Multiply the second by zz: u=z+2zuF=z+2zu/(1−u)u = z + 2zuF = z + 2zu/(1-u). Clear the denominator: u−u2=z+zuu - u^2 = z + zu, so u2−(1−z)u+z=0.u^2 - (1 - z)u + z = 0. The root with u(0)=0u(0) = 0 is u=1−z−1−6z+z22,u = \frac{1 - z - \sqrt{1 - 6z + z^2}}{2}, because (1−z)2−4z=1−6z+z2(1-z)^2 - 4z = 1 - 6z + z^2. Therefore ∑n≥0bnzn=1+u=3−z−1−6z+z22.\sum_{n \ge 0} b_n z^n = 1 + u = \frac{3 - z - \sqrt{1 - 6z + z^2}}{2}.

A recurrence. Put BB in the form B2−(3−z)B+2=0B^2 - (3-z)B + 2 = 0. The coefficient of znz^n gives bn=bn−1+∑k=1n−1bkbn−kb_n = b_{n-1} + \sum_{k=1}^{n-1} b_k b_{n-k} for n≥2n \ge 2. Differentiating the closed form gives also n bn=3(2n−3) bn−1−(n−3) bn−2(n≥2).n\,b_n = 3(2n-3)\,b_{n-1} - (n-3)\,b_{n-2}\qquad (n \ge 2).

Check

The series of the closed form is 1+z+2z2+6z3+22z4+90z5+394z6+1806z7+⋯1 + z + 2z^2 + 6z^3 + 22z^4 + 90z^5 + 394z^6 + 1806z^7 + \cdots. The first values agree with the counts of the admissible sequences found by search in Exercise 2.2.1-10. I checked the weighted sum over Dyck words for n≤7n \le 7, with results 1,2,6,22,90,394,18061, 2, 6, 22, 90, 394, 1806. The coefficient recurrence and the three-term recurrence both gave bnb_n up to n=59n = 59, with equal values.

Remarks

The numbers bnb_n for n≥1n \ge 1 are the large Schröder numbers 1,2,6,22,90,394,…1, 2, 6, 22, 90, 394, \ldots. They count Dyck-type paths with a second kind of step, so the appearance of a quadratic equation is natural. The book's answer finds the same function from a double generating function.

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.