Modue 4
Modue 4
In tree data
structure, every individual element is called as Node. Node in a tree data
structure stores the actual data of that particular element and link to next
element in hierarchical structure.
TREE TERMINOLOGIES:
1)Root Node 13) Sub Tree
2)Edge
3)Parent Node
4)Child Node
5)Siblings
6)Leaf Node
7)Internal Node
8)Degree
9)Level
10)Height
11)Depth
12)path
2. Edge: In a Tree, the connecting link between any two nodes is called as EDGE. In a tree with 'N' number of nodes
there will be a maximum of 'N-1' number of edges.
Level: In a Tree data structure, the root node is said to be at Level 0 and the
children of root node are at Level 1 and the children of the nodes which are
at Level 1 will be at Level 2 and so on... In simple words, in a tree each step
from top to bottom is called as a Level and the Level count starts with '0' and
incremented by one at each level (Step).
• BINARY TREE:
• In a normal tree, every node can have any number of children.
A binary tree is a special type of tree data structure in which every node
can have a maximum of 2 children. One is known as a left child and the
other is known as right child.
• A tree in which every node can have a maximum of two children is called
Binary Tree.
In a binary tree, every node can have either 0 children or 1 child or 2
children but not more than 2 children.
• TYPES OF BINARY TREE:
1)Strictly Binary Tree:
• In a binary tree, every node can have a maximum of two children. But in
strictly binary tree, every node should have exactly two children or none.
That means every internal node must have exactly two children. A strictly
Binary Tree can be defined as follows...
• A binary tree in which every node has either two or zero number of
children is called Strictly Binary Tree
2)Complete Binary Tree:
A binary tree in which every internal node has exactly two children and all leaf nodes are
at same level is called Complete Binary Tree.
The above example of the binary tree represented using Linked list representation is
shown as follows
BINARY TREE TRAVERSALS:
Displaying (or) visiting order of nodes in a binary tree is called as Binary Tree Traversal.
When we wanted to display a binary tree, we need to follow some order in which all the
nodes of that binary tree must be displayed. In any binary tree, displaying order of nodes
depends on the traversal method.
• There are three types of binary tree traversals.
• In - Order Traversal
• Pre - Order Traversal
• Post - Order Traversal
In - Order Traversal (left Child - root - right Child):
Algorithm:
Step-1: Visit the left subtree, using inorder.
Step-2: Visit the root.
Step-3: Visit the right subtree, using inorder.