00:00

Tree Terminology in Data Structure

A Tree is a hierarchical data structure that consists of nodes connected by edges. Each node contains a value (data) and may have zero or more child nodes. The topmost node in a tree is called the root node, and the nodes at the bottom that do not have children are called leaf nodes.

Tree Data Structure Hierachy

Terminologies in Tree Data Structure

  1. Node: In a tree, Node is an object or entity that contains data and reference (address) to its all child nodes.

    For example, In the given tree, there are total 6 Nodes (A, B, C, D, E, F).

     Node in Tree
  2. Edge: In a tree, Edge makes a connection or link between two nodes. In a tree with 'N' nodes will have a maximum of 'N-1' edges.

    For example, in the given tree below, the line connecting Nodes A and B is called an edge.

    Edge in Tree
  3. Root Node: The first node or top most node is a called a Root node, it does have a parent node and it will be a only one in a tree.

    In the given tree, A is the root node.

    Root Node in Tree
  4. Parent Node: A node that is a node's predecessor is called a Parent node in a tree. A parent node contains the referece (address) of its child nodes.

    For better understanding, lets see the tree below.

    Parent Node in Tree
  5. Child Node: The descendant node of any node is called a child node in a tree.

    For example, In the given tree, A is the root node, and B and C are child nodes of A; similarly, D and E are child nodes of B, and F is a child node of C.

     Node in Tree
  6. Sibling: In general as we know that children of the same parent are called siblings. There is a sample meaning in the tree also, two child nodes connected to a same parent node is called as sibling.

    For example, In the given tree below:

    • Nodes B and C are siblings.
    • Nodes D, E and F are siblings.
    • Nodes G and H are siblings.
    • Nodes I and J are siblings.
    Sibling Nodes in Tree
  7. Leaf Node: A node that has no child nodes is known as a leaf node. A leaf node is the tree's lowest node. Leaf nodes are also known as exterior nodes.

    For example, we can see in the below tree here D, G, I, J, H are the leaf node.

     Node in Tree
  8. Degree of a Node: The degree of a node means the total number of its children. A node with the highest degree in a tree is referred to as a degree of tree.

    For example, In the given tree below, nodes degree are as follow:

    • Node A degree is 2. (B and C are children)
    • Node B degree is 3. (D, E and F are children)
    • Node C degree is 2. (G and H are children)
    • Node E degree is 2. (I and J are children)

    Nodes D, F, I, J, G, H degree is 0 as they don't have child.

    In tree, all the leave nodes degree is 0.

     Node in Tree
  9. Height of a node: The height of a node is the total number of edges that connect a leaf node to a specific node along the longest path.

    In a tree, height of all leaf nodes will be always '0'.

    For better understanding, lets see the tree below.

    Height of a Node in Tree
  10. Depth of a node: In a tree, the total number of edges from the root node to a specific node is known as the depth of that node.

    In a tree, depth of root node will be always '0'.

    For better understanding, lets see the tree below.

    Node Depth in Tree
  11. Path: In a tree, the path between two nodes is the sequence of nodes and edges that connects them. The total number of nodes in a path defines its length.

    For better understanding, lets see the tree below.

     Node in Tree
  12. Ancestor of a Node: Any predecessor nodes on the path of the root to that node are called Ancestors of that node.

    For example, In the given tree, Nodes A and B are the ancestor nodes of node {E}.

     Node in Tree
  13. Descendant: A node x is a descendant of another node y if and only if y is an ancestor of x.

    For example, node H is descendant of node C as given in the below tree.

     Node in Tree
  14. Level of a node: Each step from top to bottom is referred to as a level in a tree. Always a root node level is 0, the next child node is at level 1, the grandchild at level 2, and so on.

    Levle of node in Tree
  15. Internal node: A node that has one or more child nodes is called an internal node; it is also known as Non-Terminal nodes.

    A leaf node will never be an internal node in a tree.

    For example, In the given tree below, nodes A, B, C, E, G are Internal Nodes and remaining are leaf nodes.

    Tree Internal Nodes
  16. Neighbour of a Node: The parent or child nodes of that node are referred to as neighbors.

    For better understanding, lets see the tree below.

     Node in Tree
  17. Subtree: In a tree, A subtree will be formed on every single parent node by each child node.

    For better understanding, lets see the tree below.

    Subtree in a Tree