Trees
Trees
Definition
In linear data structure, data is organized
in sequential order and in non-linear data
structure, data is organized in random
order.
Tree is a very popular data structure used
in wide range of applications.
A tree data structure can be defined as
follows...
A treedata structure can also be defined as
follows...
Example:
Strictly binary tree data structure is used
to represent mathematical expressions.
Example:
2. Complete 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 and in
complete binary tree all the nodes must have
exactly two children and at every level of
complete binary tree there must be
2level number of nodes.
For example at level 2 there must be 22 = 4
nodes and at level 3 there must be 23 = 8
nodes.
Example:
3. Extended Binary Tree
A binary tree can be converted into Full
Binary tree by adding dummy nodes to
existing nodes wherever required.
Example:
The above tree is a binary search tree and every node is satisfying balance
factor condition. So this tree is said to be an AVL tree.
AVL Tree Rotations
In AVL tree, after performing every operation like
insertion and deletion we need to check
the balance factor of every node in the tree.
If every node satisfies the balance factor condition
then we conclude the operation otherwise we must
make it balanced.
We use rotation operations to make the tree
balanced whenever the tree is becoming
imbalanced due to any operation.