A
|
B
|
C
|
D
|
|
E
|
F
|
0
|
1
|
2
|
3
|
4
|
5
|
6
|

Binary Tree Representation
Share This
Binary
Tree Representation:
Binary
trees can be represented in in two ways.
1. Sequential
or Array representation.
2. Linked
List representation.
Sequential
representation of Binary Trees:
In
sequential representation binary tree is represented with help of a single
dimensional array. The size of the array can be determined as 2(d+1)-1, where d
is the depth of the tree. The root element is always placed at first position
of the array (i.e., 0) and the left child is placed at twice the root position
+1 and right child is placed at twice the root position +2 positions.
Position
of left child I = (2*root position) +1
Position
of right child = (2*root position) +2
E.g.:
size of array = 2(d+1)-1=2(2+1)-1=7
The
binary tree can be represented as
Representation of binary tree using arrays is very simplest
and easiest. But array representation has so many drawbacks. The insertion and
deletion of nodes in the middle of a tree requires the moment of many nodes to
reflect the change in level number of these nodes. And also a binary tree with
a few nodes will have lot of un utilized space in the array. More over the size
of arrays is fixed in nature, adding new nodes is complex since the size of the
array has to increase. To overcome this disadvantages Linked list
representation is used.
Linked
Representation:
In
order to represent a binary tree using linked list a Double linked list is
used. Since every node contains three fields one to hold the data and the other
two fields to hold the address of left and right child nodes.
The
structure of Node is as follows
Where Data/ info holds the data associated with the Node
Left and right are address fields which hold the address of the left and right sub trees.
class
Node
{
int idata;
double fdata;
Node left;
Node right;
}
The
binary can be represented as
Tags
# Data Structures
Share This

About M Vishnuvardhan Reddy
Myself Today DotNet Consultant and faculty in Sri Sai Baba National Degree College, Anantapur, AP, India. Started with C, ORACLE and today well-versed with top Microsoft Technologies ASP.NET,C#.NET also SQL SERVER. Latest Developments JQuery, CSS etc. Interested to implement always new and wanted technologies. Love to hear comments from u for my posts.
Applications of Stack Data Structure
M Vishnuvardhan ReddyNov 26, 2020Expression Trees
M Vishnuvardhan ReddyMay 22, 2020Binary search tree
M Vishnuvardhan ReddyMay 21, 2020
Tags:
Data Structures
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment