Introduction
A tree is a Data Structure in which the elements are stored in hierarchical order. A tree is also defined as an acyclic graph or a graph with no cycle. A tree is made up of nodes and edges, where nodes represent the values at that point and edges represent some relation or connection between the nodes.
Fig 1. Tree Data structure
Properties of Tree
-
Root Node: It is a specially designed data item in a tree. It is the first in the hierarchical arrangement of data items. The number of incoming edges to this node is zero.
-
Node: Each data item in a tree is called a node. It is the basic structure of a tree. It specifies the data information and links to other data items.
-
Degree of node: It is defined as the number of children of a node.
-
Degree of Tree: The degree of a tree is the maximum degree of any of its nodes.
-
Terminal Nodes/Leaf nodes: A node with the degree of zero or a node that has no child is called a terminal node or a leaf node.
-
Non-Terminal Node: Any node (except the root node) whose degree is not 0 or any node that has both in-degree and out-degree.
-
Siblings: The children node of a given parent node are called siblings.
-
Level: The root node is on level 0, the children of the root node are at level 1, and the children of level 1 node are at level 2 and so on.
-
Edge: The connections between the nodes are represented with the help of edges. If a tree has n nodes, then there are n-1 edges.
-
Height/Depth: It is defined as the number of levels in a tree.
- Forest: It is a collection of more than one tree that is not connected.