Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
0 of .
Results for:
P. 1
a complete guide for building a AVL Tree

# a complete guide for building a AVL Tree

Ratings:

4.67

(1)
|Views: 10,250|Likes:
a complete guide for inserting & deleting nodes in a AVL Tree.........by following this tutorial any body new to data structure, can make a correct and complete AVL tree , which is generally a sore point for not only beginners also the pros.
a complete guide for inserting & deleting nodes in a AVL Tree.........by following this tutorial any body new to data structure, can make a correct and complete AVL tree , which is generally a sore point for not only beginners also the pros.

### Availability:

See more
See less

02/01/2013

pdf

text

original

1
Suvayan 9231937821 suvayanbala@gmail.com

Page | 1
Drawing an AVL TREE:-
Steps for insertion:-
1.

Insert the numbers in Binary Search Tree (BST)pattern.2.

Before the next number is inserted, perform thefollowing operations :-a)

Find out the balance factor of each node.

b)

Balance Factor of a node = (Maximum numberof levels that can be reached in right sub-tree ) – ( Maximum number of levels that can bereached in left sub tree )[WE TAKE LEVEL OF THE STARTING NODEAS 0]c)

If any of the Balance Factor is (-2) or (2),perform required rotation according to thealgorithm given below. If two nodes have (2/-2)then select the lowest node in level.d)

The tree now become balanced, i.e. no nodehas Balance Factor (-2) or (2). Continue fromstep 1.
Rotation Algorithm
[Right heavy (B.F. = 2), Left heavy (B.F. = -2)]

IF tree is right heavy (B.F. = 2)IF tree's right sub tree is left heavy (B.F. = -2 / -1)Perform Left-Right (LR) rotation

2
Suvayan 9231937821 suvayanbala@gmail.com

Page | 2
}ELSEPerform Left rotation } }ELSE IF tree is left heavy (B.F. = -2)IF tree's left sub tree is right heavy (B.F. = 2 / 1)Perform Right-Left Rotation (RL) rotation }ELSEPerform Right rotation } }
ROTATIONS
Left Left Case Right Right Case

( Right Rotation ) (

Left Rotation )

3
Suvayan 9231937821 suvayanbala@gmail.com

Page | 3
Left - Right Case ( LR Rotation )

Left rotation Right rotation
Right - Left Case ( RL Rotation )