Unit - 3 Tree
Unit - 3 Tree
DATA STRUCTURE
Tree Data Structure
• Insert 70-
• As 70 > 50, so insert 70 to the right of 50.
Binary Search Tree Construction
Insert 60-
As 60 > 50, so insert 60 to the right of 50.
As 60 < 70, so insert 60 to the left of 70.
Insert 20-
As 20 < 50, so insert 20 to the left of 50.
Binary Search Tree Construction
Insert 90-
As 90 > 50, so insert 90 to the right of 50.
As 90 > 70, so insert 90 to the right of 70.
Binary Search Tree Construction
• Insert 10-
• As 10 < 50, so insert 10 to the left of 50.
• As 10 < 20, so insert 10 to the left of 20.
Binary Search Tree Construction
• Insert 40-
• As 40 < 50, so insert 40 to the left of 50.
• As 40 > 20, so insert 40 to the right of 20.
Binary Search Tree Construction
• Insert 100-
• As 100 > 50, so insert 100 to the right of 50.
• As 100 > 70, so insert 100 to the right of 70.
• As 100 > 90, so insert 100 to the right of 90.
Practice Problem
A binary search tree is generated by inserting in order
of the following integers-
50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24
100,1,10,30,50,60,70,45,55
Dec,jan,march,may,june,july,aug,april,sept,oct,nov,feb
Binary Search Tree Operations
AVL TREE
• Named after their inventor Adelson, Velski & Landis,
AVL trees are height balancing binary search tree.
• AVL tree checks the height of the left and the right
sub-trees and assures that the difference is not more
than 1.
• This difference is called the Balance Factor.
• BalanceFactor =height(left-sutree)−height(right-sutree)
EXAMPLE OF AVL TREE
AVL Rotations
State Action
Node C is still unbalanced, however
now, it is because of the left-subtree
of the left-subtree.