1. BABA GHULAM SHAH BADSHAH
UNIVERSITY- RAJOURI (J&K).
DEPARTMENT OF COMPUTER
SCIENCES
PRESENTATION TOPIC:-
PRESENTED BY:-
Ajeela Mushtaq Roll NO:-13-Mcs-15
PRESENTED TO:-
MUZAFAR AHMAD DAR
CONCEPT OF AVL TREE AND B-TREE
2. AVL Tree
• AVL tree was introduced by Russian
Mathematicians G.M. Adelson- Velskii and E. M.
Landis in 1962.
• It’s a binary tree in which the height of left sub tree
to the height of right sub tree differs at most by 1.
This difference is called Balance Factor.
3. • Here we see that the first tree is balanced and next
two trees are not balanced −
4. • In second tree, the left sub tree of C has height 2 and
right sub tree has height 0, so the difference is 2. In third
tree, the right sub tree of A has height 2 and left is
missing, so it is 0, and the difference is 2 again. AVL tree
permits difference (balance factor) to be only 1.
Balance Factor = height(left-sub tree) − height(right-sub
tree)
• If the difference in the height of left and right sub-trees is
more than 1, the tree is balanced using some rotation
techniques.
5. B-Tree
• The trees discussed already contain only one
key information in each node.
• If the nodes have two links then they are binary
trees.
• If more than two links generate from the node
then it is multi way tree.
6. • The concept of B-Tree was developed by two scientists
Bayer and Crugit in 1972.
• A multi-way balanced tree is called as B-Tree. Each node
in a B-Tree contains more than one key information in an
order, either in ascending or descending.
• B-Tree is not a binary tree.
7. Contd…
• It grows from bottom to top rather than top
to bottom .
• Because of the multi-ways the B-Tree is
also called as m-way tree.
8. PROPERTIES:
• Each node has maximum of m-1 keys.
• Each node has a maximum of ‘m’ links, means they
can have maximum of ‘m’ children.
• Each node contains keys in order.
• All the leaves will be at same level.
• If a node contains m-1 keys then it is said to be full.
In a full node if key is added, then the node will be
split at median key value and the median will move
to root or as a value in root. So, the node is split into
leaves and root.
9. Contd…
• The insertion is always done at the leaves.
• Root node of B-Tree should contain at-least one key.
10. Example of B-Tree
• Design a B-Tree of order 5 from
the following list of numbers ?
12,32,8,18,34,21,11,10,9,20
11. Solution..
• As the order of B-tree is 5 ,we can store maximum of
4 numbers in each node. The maximum links of any
node will be 5.
• The first number 12 is inserted into an empty node
of a B-Tree.
• The next number 32 is added to the node after 12 .
Similarly 8 is added to the node before 12 and 18 is
added after 12.
12
12. Contd…
• After three insertions the B-Tree will be.
• When 34 is added to the node , the node will be full
and needs a split . The node is split at median 18
and a root node with key (number) 18 is created and
two leaves are formed. So, the B-Tree after insertion
will be
8 12 18 32
18
32
34
8 12
13. Contd…
• The next no. 21 is added to the right child (before 32)
of 18 because 21 is greater than 18.the next no. 11
is added to the left child of 18(between 8 and 12).
Similarly the next no. 10 is added to the left child of
18(between 8 and 11). The B-Tree after these two
insertion is:
18
8 10 11 12 21 32 34
14. Contd…
• When the next no.9 is to b added to the B-Tree it is
supposed to be added to the left child of 18. As the
left child will be full after this addition the node will
be split. The median 10 will be moved to root . The
next no. 20 is added to the right child of 18 (before
21). After this the B-Tree will be:
10 18
8 9 11 12 20 21 32 34