TREE DEFINITION IN DATA STRUCTURE


TREE

A tree t can be a defined as finite(means limit or not infinite) set of nodes in which there is one specially designated node known as root of the tree.

and the remaining nodes are partitioned into disjoint sets t1, t2….tn such that each t1 is itself a tree and is known as sub-tree of its root.

tree

                                                                               A general tree

A line which is connects a parent node to its child node is called an edge or branch.

All the nodes in a tree except the root node, has a parent node associated with it.

A  node in the tree can have zero or more children called its successors.

A node having no child is called a leaf node or terminal node. sometimes, it is also known as external nodes and non-terminal nodes are called internal nodes.

Nodes having same parent node are called siblings or brothers.

  • In the above figure, A is the root having three children B, C and D.
  • B,C and D are siblings as these have the same parent node A.
  • similarly,K and L are also known as siblings having same parent E.
  • K,L,M and N are the leaf nodes having no child.

A path between any two nodes in a tree is a sequence of distinct nodes in which successive nodes are connected by the edges.There must be exactly one path between the root and any other node in the tree. If there is more than one path between any two nodes then that is not a tree but a graph.


The length of a path zero from every node to itself. In the above figure, A->N->E->K which is length 3.

The height of any node in a tree is the length of  the longest path from that node to a terminal node i.e node B is at height of 2 and node E is at height of 1.

The degree of node can be defined as number of child nodes it has. Node A has degree 3 and G has degree 1.

The weight of the tree is the number of external nodes available in that tree. In the above figure, weight is 7 i.e  K,L,F,M,H,N and J are external nodes.

Each node is assigned a level number which comes from the length of the path from the root to that node. Root of a tree is said to be at level 0.

The level also known as depth of the tree, of any node is the number of edges that are to travelled from the root node to that particular node.

Leave a comment