Mark the empty children
transcript
A tree must be saved as text. Later you must load it back. The text must name the exact tree. Here is the rule that makes it so.
Pick one fixed order, such as preorder. Write each value as you visit it. Write a marker for each missing child.
Root four, then its left child two. Two has a left child one. One has no children, so two markers. Two has no right child, so one marker. Then six, with two markers.
Four nodes write four values. They also write five markers. Nine tokens in total.
The same walk can compare two trees with each other. It can also be stored as text and rebuilt later. And it can guide a relink of the nodes in place.
Reading back, a value makes a node. A marker means no node, so go back up.
Fixed order, with markers. The walk is the tree. Full breakdown in the lecture.