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

Exercise 2.3-3

not stated yet in Lean solution written

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

The task

Prove from the definition of a tree that for each node XX there is exactly one path X1,X2,…,XkX_1, X_2, \ldots, X_k with X1X_1 the root, Xk=XX_k = X and XjX_j the parent of Xj+1X_{j+1}.

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 induction on the number of nodes of the tree. Split off the root and the subtrees.

Hint 2

Prove two facts: a path exists, and each node other than the root has exactly one parent.

Solution

Show the solution

Recall the definition. A tree is a finite nonempty set of nodes. One node is the root. The other nodes are split into m≥0m \ge 0 disjoint sets, and each set is a tree, the subtrees. The root of each subtree has the root of the whole tree as its parent. Inside a subtree, the parent relation is the one of that subtree.

Claim 1 (a path exists). Induction on the number nn of nodes. For n=1n = 1 the only node is the root, and the path is X1=XX_1 = X. Let n>1n > 1. If XX is the root, the path is again X1=XX_1 = X. Otherwise XX lies in one subtree TjT_j, which has fewer than nn nodes. By the induction hypothesis TjT_j has a path Y1,…,Ys=XY_1, \ldots, Y_s = X with Y1Y_1 the root of TjT_j. The root RR of the whole tree is the parent of Y1Y_1. So R,Y1,…,YsR, Y_1, \ldots, Y_s is a path in the whole tree.

Claim 2 (each node except the root has one parent). Induction on nn again. For n=1n = 1 there is nothing to prove. Let n>1n > 1 and let XX be a node other than the root RR. Then XX lies in exactly one subtree TjT_j, because the subtrees are disjoint. If XX is the root of TjT_j, its parent is RR, and no other node is its parent, because parents link nodes of the same subtree or link RR to a subtree root, and the root of TjT_j has no parent inside TjT_j. If XX is not the root of TjT_j, then XX has one parent in TjT_j by induction, and no node outside TjT_j is a parent of XX.

Now take two paths X1,…,XkX_1, \ldots, X_k and X1′,…,Xl′X'_1, \ldots, X'_l that both end in XX and both start at the root. The root has no parent. If X=RX = R, a path with k>1k > 1 would give the root a parent, so both paths are the one-element path. If X≠RX \ne R, then Xk−1X_{k-1} and Xl−1′X'_{l-1} are both parents of XX. By Claim 2 they are equal. Repeat the argument for Xk−1X_{k-1}, and so on. The two paths agree in every position, and k=lk = l because both end when the root is reached.

Check

For the tree of Fig. 19 in the text (root AA, with BB and CC below it), a python3 program listed the path from the root to each of the 9 nodes by following parents upward. Each node gave one path. For GG the path is A,C,E,GA, C, E, G.

Remarks

The same two-part induction proves most of the elementary facts about trees, so it is worth learning well.

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.