0% found this document useful (0 votes)
41 views7 pages

Data Structure Avl Tree

Here is the AVL tree for the given nodes: 3 \ 2 \ 1 / 4 / 5 \ 6 \ 7

Uploaded by

Asma Noreen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views7 pages

Data Structure Avl Tree

Here is the AVL tree for the given nodes: 3 \ 2 \ 1 / 4 / 5 \ 6 \ 7

Uploaded by

Asma Noreen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

DATA STRUCTURE

AVL TREE

Submitted by:

Anosha farid Roll No. 34

Saba Qayyum Roll No.35

Asma Noreen Roll No.36

Maryam Sohail Roll No.38

Submitted to:

Ma’am Sehrish Raza.

WOMEN UNIVERSITY MULTAN.


AVL TREE

Introduction:

An AVL tree is a balancing binary search tree. It is named after Adelson, Velski and
Landis. It was a first data structure to be invented. In an AVL tree, the heights of
the two child sub-trees of any node differ by at most one; if at any time they differ
by more than one, rebalancing is done to restore this property. Lookup, insertion,
and deletion all take O(log n) time in both the average and worst cases, when n is
the number of nodes in the tree prior to the operation. Insertions and deletions
may require the tree to be rebalanced by one or more tree rotations. The balance
factor of AVL tree could be found by the following formula.

BF=hl-hr

Note: The BF of a node can be 0, 1 or -1.

AVL tree Insertion process:

Insertion of AVL tree is similar to Binary Search Tree. After insertion,we have to fix
the AVL tree. A technique called rotation is used to restore the balance of AVL
tree. Following are the rotations.

 Left Rotation.
 Right Rotation.
 Left Right Rotation.
 Right Left Rotation.
 Left Rotation:

In LL (Left Left) Rotation, the inserted node is in the left sub-tree of the left sub-
tree of node A.

We use balance factor there to check whether it is AVL tree or not.

BF=height of left – height of right

Example:

A
B

A C

C
 Right Rotation:

In RR (Right Right) Rotation, the inserted node is in the right sub-tree of right sub-tree of node
A.

Example:

B
C A

Right Rotation
 LR Rotation:

In LR (Left Right) Rotation, node is inserted in the right of left sub tree. It makes the tree
unbalanced. It is also known as Double Rotation.

Example: A

A C

B
Left Rotation Right Rotation
B
A B

C C
Left Right Rotation

 Right Left Rotation:

In RL (Right Left) Rotation, node is inserted into left of right sub-tree.

Example:
A

A
C

B Right Rotation B Left Rotation


A B

C C
Draw an AVL tree from the following nodes:

3,2,1,4,5,6,7.

You might also like