Exercise · Volume 1 · 2.3-20
Exercise 2.3-20
not stated yet in Lean solution written
| Rating | M21 |
|---|---|
| Markers | M (mathematical), recommended |
| Kind | K1, prove: show that a stated fact is true from the written solution |
| Section | Section 2.3 of Volume 1 |
The task
A 0-2-tree is a tree in which each node has 0 or 2 children. Show that each 0-2-tree has an odd number of nodes, and give a one-to-one correspondence between binary trees of nodes and 0-2-trees of nodes.
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
A 0-2-tree is one node, or a root with two 0-2-trees. Use induction on this form for the parity.
Hint 2
Map the empty binary tree to the one-node tree. Map a root with left and right subtrees to a root with the images of the subtrees.
Solution
Show the solution
Odd size. A 0-2-tree has one node, or a root and two 0-2-trees. By induction on the number of nodes, a tree of one node has size , which is odd. A tree with a root and two subtrees of sizes and has size . Both and are odd by induction, so their sum is even, and the total is odd.
The map. Define from binary trees to 0-2-trees by recursion. is the 0-2-tree with one node. If has a root , a left subtree and a right subtree , then is the 0-2-tree with a root and two children subtrees and in this order. The root of corresponds to the root .
Size. A binary tree of nodes goes to a 0-2-tree of nodes. For the size is . For , with and , , the size is .
One to one. Each 0-2-tree with more than one node has a root and exactly two children subtrees, so it is the image of exactly one binary tree, built from the preimages of the two subtrees. The tree with one node is the image of only. So has an inverse: remove the leaves of the 0-2-tree. By induction on the size of the 0-2-tree, is a bijection from the binary trees with nodes onto the 0-2-trees with nodes.
Check
Python3 counted 0-2-trees by the number of nodes. The counts for are , which is zero for even . For , , the counts are . These are the numbers of binary trees with nodes, .
Remarks
The interior nodes of a 0-2-tree are the nodes of the binary tree, and the leaves are the empty subtrees. This is the idea of an extended binary tree.
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.