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

Exercise 2.3-22

not stated yet in Lean solution written

Rating21
Markersrecommended
KindInformal: the exercise has no formal statement, so Lean does not state it from the written solution
SectionSection 2.3 of Volume 1

The task

Design a picture of a binary tree that uses the A-series paper sizes, where cutting a sheet in half gives two sheets of the next size, and draw tree (1) of Section 2.3.1 in it.

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 A sheets all have the ratio 2:1\sqrt{2} : 1. Cut a sheet across its long side, and the two halves are again of this ratio, turned by a quarter turn.

Hint 2

Let a node be a point at the center of its sheet. Its subtrees take the two halves.

Solution

Show the solution

Scheme. The picture of a binary tree is built by recursion on a rectangle of ratio 2:1\sqrt{2} : 1.

  1. If the tree is empty, draw nothing.
  2. Otherwise draw a dot at the center of the rectangle. Cut the rectangle across its long side into two halves. Each half has the ratio 1:21 : \sqrt{2} again, so it is a smaller sheet turned by a quarter turn.
  3. Draw the left subtree in the first half (the left half or the top half) and the right subtree in the second half, by the same rule. Join the dot to the center dots of the two subtree pictures with straight segments.

Every rectangle has the same shape, so the rule can go on without end. The area of the sheet of a node is half the area of the sheet of its parent, so a node at level kk has the area 2−k2^{-k} of the page. Segments do not cross: the segments from a node run along the axis through its center that is parallel to the long side of its sheet, and each segment stays inside the sheet of the node.

Tree (1) is AA with left subtree BB (whose left child is DD) and right subtree CC. The node CC has the left subtree EE (with right child GG) and the right subtree FF, whose children are HH and JJ. Take a sheet of width 2\sqrt{2} and height 11 with the origin at the top left. The cuts alternate: vertical for AA, horizontal for BB and CC, vertical for DD, EE and FF. The centers of the nodes, computed by python3, are:

node xx yy
AA 0.707 0.500
BB 0.354 0.500
CC 1.061 0.500
DD 0.354 0.250
EE 1.061 0.250
FF 1.061 0.750
GG 1.237 0.250
HH 0.884 0.750
JJ 1.237 0.750

The edges are AA to BB and CC, BB to DD, CC to EE and FF, EE to GG, and FF to HH and JJ. The sketch below shows the picture, with the long side horizontal. The colons mark the first cut.

|-----------------------------|
|       D      :       E--G   |
|       |      :       |      |
|       B------A-------C      |
|              :       |      |
|              :   H---F--J   |
|-----------------------------|

The computer check showed that all nine sheets have the ratio 2\sqrt{2} to 11 or its inverse.

Remarks

Knuth's answer gives two other layouts, one with the root as a line and one with boxes for empty subtrees. The layout above differs from both, since it draws a dot at the center of the sheet. Which layout is best depends on whether the information is in the nodes or in the empty subtrees.

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.