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

Exercise 2.3-1

not stated yet in Lean solution written

Rating18
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 2.3 of Volume 1

The task

A tree has the three nodes AA, BB, CC. Count the different ordered trees that can be formed, where the order of the subtrees of a node matters.

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

Choose the root first. Then look at the two ways in which the other two nodes can hang below it.

Hint 2

The other two nodes are either two one-node subtrees, in two orders, or one subtree with two nodes.

Solution

Show the solution

There are three choices for the root. Say the root is AA. The nodes BB and CC then form the subtrees of AA in one of two ways.

Case 1: two subtrees with one node each. They can stand in the order B,CB, C or in the order C,BC, B. This gives 2 trees.

Case 2: one subtree with both nodes. Its root is BB or CC, and the other node is its only child. This gives 2 trees.

So each root gives 2+2=42 + 2 = 4 trees, and the total is 3⋅4=123 \cdot 4 = 12.

Answer: 12.

Check

A python3 program built every ordered tree on the labels 0,…,n−10, \ldots, n-1 as a nested tuple and counted them. The counts for n=1,2,3,4,5n = 1, 2, 3, 4, 5 are 1,2,12,120,16801, 2, 12, 120, 1680. They agree with the formula n! Cn−1n!\,C_{n-1}, where CkC_k is the Catalan number. For n=3n = 3 this is 6⋅2=126 \cdot 2 = 12.

Remarks

The count for trees where the order of siblings does not matter is exercise 2.3-2.

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.