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

Exercise 2.3-7

not stated yet in Lean solution written

Rating23
KindK1, prove: show that a stated fact is true from the written solution
SectionSection 2.3 of Volume 1

The task

Extend the definition of the previous exercise to all m≥−1m \ge -1 and all n≥−(m+1)n \ge -(m+1), so that any two nodes XX and YY of a tree have exactly one pair (m,n)(m, n) for which XX is an mmth cousin of YY, nn times removed.

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

The old condition says that pm+1(X)=pm+n+1(Y)p^{m+1}(X) = p^{m+n+1}(Y) and that pm(X)≠pm+n(Y)p^m(X) \ne p^{m+n}(Y). The new ranges let an exponent be 00, and the second condition then has an exponent −1-1.

Hint 2

Make the second condition true by convention when one of its exponents is −1-1. Then prove the claim with the nearest common ancestor of XX and YY.

Solution

Show the solution

Let j=m+1j = m + 1 and k=m+n+1k = m + n + 1. The ranges m≥−1m \ge -1 and n≥−(m+1)n \ge -(m+1) say exactly that j≥0j \ge 0 and k≥0k \ge 0.

Definition. XX is an mmth cousin of YY, nn times removed, if pj(X)=pk(Y)p^j(X) = p^k(Y) (both defined), and in addition either j=0j = 0 or k=0k = 0, or pj−1(X)≠pk−1(Y)p^{j-1}(X) \ne p^{k-1}(Y).

For j,k≥1j, k \ge 1 this is the definition of exercise 2.3-6. For j=0j = 0 the first condition says X=pk(Y)X = p^k(Y). For k=0k = 0 it says Y=pj(X)Y = p^j(X). In these two cases the second condition is true by convention.

Let ZZ be the nearest common ancestor of XX and YY, where a node counts as an ancestor of itself. It exists because the root is a common ancestor, and it is unique because the ancestors of a node form a chain. Let qq be the number of steps from XX up to ZZ, and let rr be the number of steps from YY up to ZZ. If q,r≥1q, r \ge 1, the nodes pq−1(X)p^{q-1}(X) and pr−1(Y)p^{r-1}(Y) are children of ZZ, and they are different. Otherwise they would be equal, and this common child would be a common ancestor below ZZ.

Existence. Take j=qj = q and k=rk = r. Then pj(X)=Z=pk(Y)p^j(X) = Z = p^k(Y). If j,k≥1j, k \ge 1 the second condition holds by the remark above. If j=0j = 0 or k=0k = 0 it holds by convention. So the relation holds with m=q−1m = q - 1 and n=r−qn = r - q. These satisfy m≥−1m \ge -1 because q≥0q \ge 0, and n≥−(m+1)=−qn \ge -(m+1) = -q because r≥0r \ge 0.

Uniqueness. Suppose the relation holds for some j,kj, k. Put W=pj(X)=pk(Y)W = p^j(X) = p^k(Y). Then WW is a common ancestor, so WW is ZZ or an ancestor of ZZ. Suppose W≠ZW \ne Z. If j=0j = 0, then W=XW = X is an ancestor of YY, and the nearest common ancestor of XX and YY is then X=WX = W, which contradicts W≠ZW \ne Z. The case k=0k = 0 is the same. If j,k≥1j, k \ge 1, both pj−1(X)p^{j-1}(X) and pk−1(Y)p^{k-1}(Y) are children of WW on the paths from WW down to XX and YY. Both paths pass through ZZ, which is below WW, so both nodes equal the child of WW on the path to ZZ. They are equal, and this contradicts the second condition. So W=ZW = Z. Then j=qj = q and k=rk = r, and (m,n)(m, n) is determined.

Check

Python3 built 200 random trees with up to 12 nodes. For every ordered pair (X,Y)(X, Y) it searched all mm from −1-1 to 1414 and nn from −(m+1)-(m+1) to 1515. Each pair satisfied the definition for exactly one (m,n)(m, n). For example, in Fig. 19, HH and FF give (1,0)(1, 0).

Remarks

For m=−1m = -1 the node XX is an ancestor of YY (or equal to it), and for n=−(m+1)n = -(m+1) it is the other way round. The pair (−1,0)(-1, 0) means X=YX = Y.

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.