Tree traversal
Tree traversal refers to the way we visit each node in a given tree. Based on how we do the traversing, we can follow three different ways of traversing. These traversals are very important in many different ways. Polish notation conversion for expression evaluation is one of the most popular examples of using tree traversals.
In-order
In-order tree traversal visits the left node first, then the root node, and followed by the right node. This continues recursively for each node. The left node stores a smaller value compared to the root node value and right node stores a bigger value than the root node. As a result, when we are applying in-order traversing, we are obtaining a sorted list. That is why, so far, our binary tree traversal was showing a sorted list of numbers. That traversal part is actually the example of an in-order tree traversal. The in-order tree traversal follows these principles:
- Traverse the left subtree by recursively calling the in-order function.
- Display...