#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 1::2.3.2 Binary Tree Representation of Trees
#columns:Front	Back	Tags
TAOCP §2.3.2 Binary Tree Representation of Trees: what does it cover?	Any general tree or forest can be stored as a binary tree using the &quot;first child, next sibling&quot; trick. Knuth applies it to symbolic differentiation of algebraic formulas stored as trees.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::about
TAOCP §2.3.2: why does it matter?	The child-sibling representation is how many compilers and file systems store variable-arity trees. Symbolic differentiation is a mini compiler pass, so it should feel familiar after Crafting Interpreters.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::why
TAOCP §2.3.2, a common trap: “Forgetting that preorder of the forest equals preorder of the binary tree, but postorder of the forest corresponds to inorder of the binary tree.” What's the catch?	Check it on an example.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::trap
TAOCP §2.3.2, exercise 1 (rated 20, recommended): what is it asking?	Define the reverse mapping, from a binary tree back to a forest.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercise
TAOCP §2.3.2, exercise 2 (rated 20, recommended): what is it asking?	Relate Dewey numbers in a forest to those in its binary tree.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercise
TAOCP §2.3.2, exercise 4 (rated 19): what is it asking?	True or false on leaf positions in preorder and postorder.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercise
TAOCP §2.3.2, exercise 11 (rated 15): what is it asking?	Draw the trees the differentiator would store for a small formula.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercise
TAOCP §2.3.2, exercise 18 (rated 25, recommended): what is it asking?	Turn a parent table into a preorder doubly linked list efficiently.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercise
TAOCP §2.3.2, exercise 20 (rated M22, recommended): what is it asking?	Prove the ancestor test using preorder and postorder positions. A trick real tree queries use.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercise
TAOCP §2.3.2, exercise 13 (rated 26, recommended): what is it asking?	Write the tree copy subroutine in MIX for the differentiator.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercise
TAOCP §2.3.2, exercise 22 (rated M26, recommended): what is it asking?	Tree embedding, a partial order on trees. The stretch.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercise
TAOCP §2.3.2: how many exercises, and how are they rated?	22 exercises, rated 15 to M40.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::exercises
TAOCP §2.3.2: what should you be comfortable with first?	<ul><li>2.3.1 Traversing Binary Trees</li><li>Basic derivatives</li></ul>	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::prereqs
TAOCP §2.3.2: how should you work through it?	Convert a few small forests to binary trees by hand. Then implement a tiny symbolic differentiator over an expression tree in any language. It is a fun weekend project.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::2.3.2 cracked.guide::kind::approach
