TAOCP 2.3 Exercise 16

For the expression $2(a - b/c)$, the corresponding tree has the multiplication $2 \cdot (\cdot)$ at the root.

Section 2.3: Trees

Exercise 16. [**] [20] Draw trees analogous to Fig. 21 corresponding to the arithmetic expressions (a) $2(a - b/c)$; (b) $a + b + 5c$.

Verified: no
Solve time: 35s


For the expression $2(a - b/c)$, the corresponding tree has the multiplication $2 \cdot (\cdot)$ at the root. Its single child is a subtraction node representing $a - b/c$. This subtraction node has two children: the left child is the leaf $a$, and the right child is a division node representing $b/c$, with leaves $b$ and $c$ as its children.

For the expression $a + b + 5c$, the tree is rooted at an addition node corresponding to the left-associative sum $(a + b) + (5c)$. The left child of the root is an addition node for $a + b$, with leaves $a$ and $b$. The right child is a multiplication node $5 \cdot c$, with leaves $5$ and $c$.

This completes the solution. ∎