A tree data structure
A tree data structure looks very much like a real tree, the kind you can see in a garden or by the roadside. If we look at a tree, we will see that it has a root that makes the stem outside of the ground. The stem splits into branches, and at the end of the branches, we find leaves. In our tree data structure, we start from the root. The root is the node that does not have any parent. The children can be thought of as being attached to the stem by lines just like the branches of a real tree. At the end, we find some nodes that have no children and hence are called leaves. The following figure shows an example of a tree:
Note that the tree is drawn upside down. The root is at the top and the leaves are below. This is just a convention that most people prefer. Think of this as the reflection of a tree on water.
A tree can be represented in many ways, but we will get started with the idea of generalization of a linked list. In the case of a linked list, a...