Background
In computer science a binary tree is a tree in which every node has zero, one or two children. If a node has children they are denoted by “left” or “right” children. A common action is to traverse the binary tree which is where we visit each node in a certain order and output the nodes values.
There are three main methods of traversal: pre-order, in-order and post-order. In this puzzle we’re going to focus on in-order traversal, which works as follows:
- Traverse the left subtree recursively by calling in-order traversal on the left child.
- Visit the root node.
- Traverse the right subtree recursively by calling in-order traversal on the right child.