Two types of binary tree representations with Example, Advantages, Disadvantages
Binary
Tree Representation
There
two types of binary tree representations ‒
•
In this representation, we store the tree in an array using index
relationships. For a node at index i
•
The root node is placed at index 0.
• Left child :
Index is calculated using the formula 2*i + 1
• Right child :
Index is calculated using the formula 2*i + 2
• Parent :
Index is calculated using the formula floor(i‒1)/2

1.
Very fast access to parent/children using fixed formula.
2.
Memory is contiguous so good cache performance.
3.
This representation serves as a simple implementation for complete binary
trees.
4.
This representation is also useful for binary heap structure.
1.
There is wastage of lot of memory when tree is not complete or sparse.
2.
This representation is not suitable for dynamic or skewed trees.
3.
The size of the tree must.
4.
Insertion and deletion operations are difficult.
In
binary tree each node will have left child, right child and data field.vi

The
left child is nothing but the left link which points to some address of left
sub‒tree whereas right child is also a right link which points to some address
of right sub‒tree. And the data field gives the information about the node. Let
us see the 'C' structure of the node in a binary tree.
typedef struct node
{
int data;
struct node *left;
struct node *right;
}bin;
The
tree with linked representation is as shown below.

1.
Dynamic size grows or shrinks as needed.
2.
It is efficient representation when the tree is sparse.
3.
The insertion and deletion operations are performed without shifting elements.
4.
This representation can represent any type of binary tree such as complete,
skewed, expression tree.
1.
There is extra memory overload due to pointers.
2.
Accessing children nodes is slower because of pointer dereferencing.
4.
For insertion and deletion of nodes from the tree using linked representation,
there is a need to allocate or deallocate the memory.
Data Structures using C PlusPlus: Chapter 6: Trees : Tag: Data Structure, C++ Programing : Types, Example, Advantages, Disadvantages - Binary Tree Representation
Data Structures using CPlusPlus
CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Electron Devices
EC25C01 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Data Structures using CPlusPlus
CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Circuits and Network Analysis
EC25C02 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Re-Engineering for Innovation
ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Engineering Drawing - Laboratory
ME25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Data Structures using CPlusPlus - Laboratory
CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Devices and Circuits Laboratory
EC25C03 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation