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.3-14

Exercise 2.3-14

not stated yet in Lean solution written

RatingM22
MarkersM (mathematical)
KindK1, prove: show that a stated fact is true from the written solution
SectionSection 2.3 of Volume 1

The task

Let SS be a nonempty finite set of strings 1.a1.⋯ .ak1.a_1.\cdots.a_k (k≥0k \ge 0, positive integers aia_i) that is closed in this way: if α.m∈S\alpha.m \in S, then α.(m−1)∈S\alpha.(m-1) \in S when m>1m > 1 and α∈S\alpha \in S when m=1m = 1. Show that SS is the set of Dewey numbers of a tree.

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

First show that 1∈S1 \in S. Then show that the children of a node α∈S\alpha \in S are α.1,…,α.d\alpha.1, \ldots, \alpha.d for some dd.

Hint 2

Group the strings that begin with 1.j1.j. Show that each group, with 1.j1.j renamed to 11, satisfies the same condition and has fewer elements. Use induction on ∣S∣|S|.

Solution

Show the solution

Claim. If SS is nonempty, finite and closed, there is a unique ordered tree whose Dewey numbers are exactly the strings of SS.

Step 1: 1∈S1 \in S. Take any element of SS. If it is α.m\alpha.m with m>1m > 1, the rule gives α.(m−1)\alpha.(m-1) in SS. If m=1m = 1, the rule gives α\alpha. Each such step decreases the sum of the length and the last number, so after finitely many steps the string is 11. Hence 1∈S1 \in S.

Step 2: the children. For a string α∈S\alpha \in S, let dd be the largest jj with α.j∈S\alpha.j \in S, or d=0d = 0 if there is none. It exists because SS is finite. By the rule, α.j∈S\alpha.j \in S for each 1≤j≤d1 \le j \le d: from α.d\alpha.d the rule gives α.(d−1)\alpha.(d-1), and so on down to α.1\alpha.1. So the strings of the form α.j\alpha.j in SS are exactly α.1,…,α.d\alpha.1, \ldots, \alpha.d.

Step 3: induction on ∣S∣|S|. For ∣S∣=1|S| = 1 we have S={1}S = \{1\}, the tree of one node. Let ∣S∣>1|S| > 1. By Step 2 with α=1\alpha = 1, the strings of SS other than 11 begin with 1.j1.j for some j∈{1,…,d}j \in \{1, \ldots, d\}. For each such jj let SjS_j be the set of strings of SS that begin with 1.j1.j (or equal 1.j1.j), where the prefix 1.j1.j is replaced by 11. Each SjS_j contains 11, since 1.j∈S1.j \in S by Step 2. Each SjS_j is finite and has fewer elements than SS, because it misses the string 11 of SS. The closure is inherited: if 1.γ.m∈Sj1.\gamma.m \in S_j then 1.j.γ.m∈S1.j.\gamma.m \in S, so 1.j.γ.(m−1)1.j.\gamma.(m-1) or 1.j.γ1.j.\gamma is in SS, and the corresponding string is in SjS_j. By induction each SjS_j is the Dewey set of an ordered tree TjT_j. Then SS is the Dewey set of the tree with root 11 and with subtrees T1,…,TdT_1, \ldots, T_d in this order. The tree is unique, because the Dewey strings determine the parent and the order of siblings.

Check

Python3 listed the 15 strings 1.a1.⋯ .ak1.a_1.\cdots.a_k with k≤3k \le 3 and ai∈{1,2}a_i \in \{1, 2\}, tried all 215−1=327672^{15} - 1 = 32767 nonempty subsets and kept the closed ones. It found 183 closed sets. The number of ordered trees with at most 2 children per node and at most 3 levels below the root is f(3)f(3), where f(0)=1f(0) = 1 and f(d)=1+f(d−1)+f(d−1)2f(d) = 1 + f(d-1) + f(d-1)^2. This gives f(1)=3f(1) = 3, f(2)=13f(2) = 13, f(3)=183f(3) = 183. The two counts agree.

Remarks

This closure condition is a third way to define a tree, next to the recursive definition and the nested sets.

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.