532 Programming and Data Structures
can only be done in a sequential manner. The binary tree is advantageous as it is a hierarchical data
structure.
A binary tree is a fixed set of nodes. It may be empty or divided into three disjoint subsets. The first
subset is called root of the tree. It contains a single element. The other two subsets are called right and
left subtrees of the main tree. The left and right branches can be vacant. Fig. 15.2 indicates a binary tree.
As shown in Fig. 15.2, the tree is formed with nine nodes named with alphabets. The first node at the
top is called the root, that is, A. Nodes B and C are its left and right subtrees, respectively. If there is no
subtree, it means an empty subtree. For example, node D does not have a right subtree and node C has
no left subtree.
The root of the binary tree is A. Node B can be either left or right subtree.
Hence, A is called the father of B. B is called the left or right son of A. A node without branches is
called a leaf. For example, E, G, J and H are leaves.
Fig. 15.3 Hierarchical structure of a tree
The hierarchical structure of a tree is illustrated in Fig. 15.3. From this figure, Node A can be called the
grandparent of G and H, because they are the children of C. Nodes B and C are brothers because their
root is same, A. In computer science, the tree data structure is represented with a root at the top and
leaves at the bottom.
The direction from leaves to root is called up and its reverse is called down. Traversing from leaves
to the root is called 'climbing' and its opposite is called 'descending/