A tree is a hierarchical collection of nodes or vertices connected by edges. Trees cannot have cycles, and only edges will exist between a node and its descended nodes or child nodes. Two child nodes of a same parent cannot have any edges in between them. Each node can have a parent other than the top node, which is also known as the root node. There can be only one root node per tree. Each node can have zero or more child nodes. In the following diagram, A is the root node, and B, C, and D are the child nodes of A. We can also say that A is the parent node of B, C, and D. B, C, and D are known as siblings as they are child nodes from the same parent, A:
The node that does not have any children is known as a leaf. In the preceding diagram, K, L, F, G, M, I, and J are leaf nodes. Leaf nodes are also known as external nodes or terminal nodes. A node...