Binary Tree Data Structure
Binary Tree Data Structure
DATA STRUCTURE
CONTENTS
1. BINARY TREE - INTRODUCTION
2. REPRESENTATION OF BINARY TREE
3. TYPES OF BINARY TREE
4. TRAVERSING OF BINARY TREE
5. OPERATIONS IN BINARY TREE
TREE DATA STRUCTURE
> Each element in a binary tree can have only 2 children, named left and right
child.
REPRESENTATION OF BINARY TREE
1) Sequential Representation
components –
● a data element
● a right reference
● a left reference
❏ The node that lies at the top of the tree is referred to as the root node.
❏ Parent nodes are those that have children.
❏ Children nodes and parent nodes are connected to each other through
references
Storing binary tree using linked list
Maximum number of nodes in a binary tree
TYPES OF BINARY TREE
1.Full Binary Tree:
● It is a special kind of a binary tree that has either zero children or
two children.
● It means that all the nodes in that binary tree should either have
two child nodes of its parent node or the parent node is itself the
leaf node or the external node
2. Complete Binary Tree
● A complete binary tree is another specific type of binary tree
where all the tree levels are filled entirely with nodes, except the
lowest level of the tree.
● In the last or the lowest level of this binary tree, every node
should possibly reside on the left side.
3. Perfect Binary Tree
● A binary tree is said to be ‘perfect’ if all the internal nodes have
strictly two children, and every external or leaf node is at the same
level or same depth within a tree.
● A perfect binary tree having height ‘h’ has 2h – 1 node.
4.Balanced Binary Tree
● A binary tree is said to be ‘balanced’ if the tree height is O(logN),
where ‘N’ is the number of nodes. In a balanced binary tree, the
height of the left and the right subtrees of each node should vary by
at most one