SlideShare a Scribd company logo
BY:- MRS. SURKHAB SHELLY
ASTT. PROF. IN COMPUTER SCIENCE
DEPT.
First-invented self-balancing binary search
tree
Named after itstwoinventors,
1. G.M. Adelson-Velsky and
2. E.M. Landis,
› published it in their 1962 paper "An
algorithm for the organization of
information."
• In an AVL tree, the heights of the
two child subtrees of any node differ by at most
one; if at any time they differ by more than one,
rebalancing is done to restore thisproperty.
• An AVL tree is a BST in which each node has
a balance factor (Bf) of +1,0 or-1.
• The balance factor of a node is the difference of the
height of the left sub tree ( hL )and height of the
right
subtree(hR)
Bf = hL-hR)
• if a node has a balance factor of +1 then its subtree
is said to be left heavy since the height of left
subtree is greater than then rightsubtree.
• if a node has a balance factor of -1 then its subtree
is said to be right heavy since the height of right
subtree is greater than then leftsubtree.
• If a node has balance factor of 0 then its subtree is
said to bebalanced.
First, its a binary
search tree...
L <=P and P <=R
RL
P
Is this a binary tree search
tree?
5 17 32 46 53
3 9 15 21 28 34 43 51 52 54 58 68
60 71 79
7712 35 56
29 70
50
An AVL tree isa balanced binary tree
Tounderstand balance we need to
understand the notion of TreeHeight
32 71
64 86 Height 0
Height 1
55 Height 2
Bydefault, nodes with no children ha
vea height of Height of 0.
71
64 86 Height 0
Height 1
55 Height 2
Height
0
Height 0 32
But, we must also understand
theconcept ofSub-trees
71Height 0 32 Height 1
55 Height 2
Height 0 64 86 Height 0
sub-tree Lhas a
height of 0 sub-tree Rhas a
height of 1
Height =max(L.height, R.height) +1
Also empty sub-trees have a Height
of -1
Height =max(L.height, R.height) +1
44 Height =2 =max(0, 1) +1
58 Height =1 =max(-1, 0) +1
91 Height =0 =max(-1,-1) +1
Anyway, the AVL Balance Property is as
follows...
For ALL nodes, the Height of the Left and
Right Sub-trees can only differ by 1.
P A Node
L R
R.height 1L.height
1. After everyinsertion
2. Check to see if an imbalance was
created.
• All you have to do backtrack up the tree
3. Ifyou find an imbalance, correct it.
4. As long as the original tree is an AVL
tree, there are only 4 types of
imbalances that can occur.
Left-Left (Single Rotation)
Right-Right(Single Rotation)
Left-Right (Double Rotation)
Right-Left(Double Rotation)
Single rotation: insert 14, 15, 16, 13, 12, 11, 10
15
• First insert 14 and
15:
14
• Now insert16.
Single
rotations:
• Inserting 16 causes AVL violation:
• Need torotate.
14
15
16
Single
rotations:
• Rotation type:
14
15
16
Single
rotations:
14
15
• Rotation restores AVL balance:
16
Single
rotations:
14
15
16
• Now insert 13 and 12:
13
12
• AVL violation -need to
rotate.
Single
rotations:
• Rotation type:
14
15
16
13
12
Single
rotations:
13
15
16
• Now insert11.
12 14
Single
rotations:
13
15
16
• AVL violation –need to
rotate
12 14
11
Single
rotations:
• Rotation type:
13
15
16
12 14
11
Single
rotations:
13
15
16
12
1411
• Now insert10.
Single
rotations:
13
15
16
12
1411
10
• AVL violation –need to
rotate
Single
rotations:
13
15
16
12
1411
10
• Rotation type:
Single
rotations:
13
15
16
11
1410 12
• AVL balance restored.
Double rotations: insert 1,2,3,4,5,7,6,9,
8
• First insert 1 and 2:
13
15
16
11
1410 12
Double rotations:
13
15
16
11
1410
• AVL violation -
rotate
1
2
12
Double
rotations:
13
15
16
11
1410
• Rotation type:
1
2
12
Double
rotations:
• Now insert3.
• AVL balance
restored:
1 10
13
15
16
11
142 12
Double
rotations:• AVL violation –
rotate:
1 10
13
15
16
11
142 12
3
Double
rotations:
• Rotation type:
1 10
13
15
16
11
142 12
3
Double rotations:
• AVL balance
restored:
1 3
13
15
16
10
142 11
12
• Now insert4.
Double rotations:
• AVL violation -rotate
1 3
13
15
16
10
142 11
12
4
Double rotations:
• Rotation type:
1 3
13
15
16
10
142 11
12
4
Double
rotations:
10
13
15
2
111 3
4 12 14 16
• Now insert5.
Double
rotations:
10
13
15
2
111 3
4 12 14 16
• AVL violation –
rotate.
5
Single rotations:
10
13
15
2
111 3
4 12 14 16
5
• Rotation type:
Single rotations:
10
13
15111 4
5 12 14 16
3
• AVL violation –
rotate.
2
7
Single rotations:
10
13
15
2
111 4
5 12 14 16
3
7
• Rotation type:
Double rotations:
10
13
15112 5
7 12 14 16
31
• AVL violation -
rotate.
4
6
Double rotations:
10
13
15
4
112 5
7 12 14 16
31
• Rotation type:
6
Double rotations:
10
13
15112 6
7
12 14 16
1
• AVL balance
restored.
4
• Now insert 9 and 8.
3 5
Double
rotations:
10
13
15
4
112 6
7
12 14 16
1
• Rotation type:
9
8
3 5
Final tree:
10
13
15112 6
8
12 14 16
1
• Tree isalmost perfectly
balanced
4
3 5
97
LLROTATION
• LL rotation is performed when the node N is
inserted in the left subtree of the left child of the
pivot nodeP.
• In order to rebalance the BSTusing LLrotation ,we
perform following steps:
• 1.the right subtree (XR) of the left child (X) of the
pivot node(P) becomes the left subtree ofP
• 2.Pbecomes right child of nodeX.
• 3.left sub tree (XL) of the node X remains
unchanged.
RR ROTATIONS
•RRrotation is performed when a node N is inserted in the
right subtree of the right child of the pivot node P. In order
to rebalance this BST using RR rotation, we perform the
following steps:
•1.Theleft subtree (YL) of the right child (Y) of the pivot
node (P) becomes the right subtree ofP.
• 2.P becomes the left child of nodeY.
•3.Right subtree (YR ) of node Yremainsunchanged.
•After RR rotation ,theAVLtree has the same height s it
had before the insertion ofnode.
LRROTATION
• LRRotation is performed when node Nis inserted
in the right subtree of the left child of the pivot
node P.
• In order to explain LRrotation,let usassumenodeX
be the left child of node P,andnode Zbe the right
child of node X.Thefollowing steps are performed
in the LRrotation.
ROTATION1:
Theleft subtree of node Z(ZL)becomes the right subtree of
node X.
2.Theleft child (node X)of the pivot node Pbecomesthe
left child of nodeZ
ROTATION2:
3.Theright subtree of node Z(ZR)becomesthe left subtree
of nodeP.
4. Pbecomes the right child of nodeZ.
RL
ROTATION
• RL( Right-Left) rotation is just mirror image of LR
rotation. It is performed when a node N is inserted in the
left subtree of the right child of the pivot node P. Like
LR rotation , it is also a double rotation process.
• Let us assume node Y be the right child of node P and
node Z be the left child of node Y. The following steps
are performed in RL rotation:
) becomes the left
Rotation 1
1. The right subtree of node Z
(ZRsubtree of node Y.
2. The right child (node Y) of the pivot node P becomes
the right child of node Z.
Rotation 2
) becomes the right3.The left subtree of node Z(
ZLsubtree of node P.
4. P becomes the left child of node Z.
AVL
tree?
YES
Each left sub-tree has
height 1 greater than each
right sub-tree
NO
Left sub-tree has height 3,
but right sub-tree has height
1
Insertion
Insert 6
Imbalance at 8
Perform rotation with 7
Deletion
Delete 4
Imbalance at 3
Perform rotation with 2
Imbalance at 5
Perform rotation with 8
Ad

More Related Content

Similar to Avl tree ppt (20)

Avl tree detailed
Avl tree detailedAvl tree detailed
Avl tree detailed
Dr Sandeep Kumar Poonia
 
DS_Mod4_2.pdf
DS_Mod4_2.pdfDS_Mod4_2.pdf
DS_Mod4_2.pdf
SankarTerli
 
Avl tree
Avl treeAvl tree
Avl tree
Dr Sandeep Kumar Poonia
 
Adelson velskii Landis rotations based on
Adelson velskii Landis rotations based onAdelson velskii Landis rotations based on
Adelson velskii Landis rotations based on
banupriyar5
 
Data structures trees and graphs - AVL tree.pptx
Data structures trees and graphs - AVL  tree.pptxData structures trees and graphs - AVL  tree.pptx
Data structures trees and graphs - AVL tree.pptx
MalligaarjunanN
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
AVL tree PPT.pptx
AVL tree PPT.pptxAVL tree PPT.pptx
AVL tree PPT.pptx
SamyakJain710491
 
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
AVL TREE PREPARED BY M V BRAHMANANDA REDDYAVL TREE PREPARED BY M V BRAHMANANDA REDDY
AVL TREE PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
Avl trees
Avl treesAvl trees
Avl trees
amna izzat
 
Presentation_30219_Content_Document_20250107125144AM.pptx
Presentation_30219_Content_Document_20250107125144AM.pptxPresentation_30219_Content_Document_20250107125144AM.pptx
Presentation_30219_Content_Document_20250107125144AM.pptx
chiraglab007
 
AVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data StructureAVL tree ( Balanced Binary Search Tree)-Data Structure
AVL tree ( Balanced Binary Search Tree)-Data Structure
Yaksh Jethva
 
Avl tree
Avl treeAvl tree
Avl tree
Ajay Singh Rana
 
Lect 13, 14 (final)AVL Tree and Rotations.pdf
Lect 13, 14 (final)AVL Tree and Rotations.pdfLect 13, 14 (final)AVL Tree and Rotations.pdf
Lect 13, 14 (final)AVL Tree and Rotations.pdf
MuhammadUmerIhtisham
 
Avl trees
Avl treesAvl trees
Avl trees
Mannan Masood
 
Avl trees
Avl treesAvl trees
Avl trees
Mannan Masood
 
Avl tree
Avl treeAvl tree
Avl tree
Shankar Bishnoi
 
C++ UNIT4.pptx
C++ UNIT4.pptxC++ UNIT4.pptx
C++ UNIT4.pptx
Kongunadu College of Engineering and Technology
 
AVL Tree.pptx
AVL Tree.pptxAVL Tree.pptx
AVL Tree.pptx
Trad5
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
Afaq Mansoor Khan
 
What is AVL trees and example based on AVL Tree
What is AVL trees and example based on AVL TreeWhat is AVL trees and example based on AVL Tree
What is AVL trees and example based on AVL Tree
Jaydeep Kale
 

More from Surkhab Shelly (18)

2020 sd college- internet of everyhing
2020 sd college- internet of everyhing2020 sd college- internet of everyhing
2020 sd college- internet of everyhing
Surkhab Shelly
 
Intro to computer
Intro to computerIntro to computer
Intro to computer
Surkhab Shelly
 
Intro to dbms
Intro to dbmsIntro to dbms
Intro to dbms
Surkhab Shelly
 
Types of keys dbms
Types of keys dbmsTypes of keys dbms
Types of keys dbms
Surkhab Shelly
 
Architecture of dbms
Architecture of dbmsArchitecture of dbms
Architecture of dbms
Surkhab Shelly
 
Er model
Er modelEr model
Er model
Surkhab Shelly
 
Output devices
Output devicesOutput devices
Output devices
Surkhab Shelly
 
SQL
SQLSQL
SQL
Surkhab Shelly
 
Structured Query Language
Structured Query LanguageStructured Query Language
Structured Query Language
Surkhab Shelly
 
Types of secondary storage devices ppt
Types of secondary storage devices pptTypes of secondary storage devices ppt
Types of secondary storage devices ppt
Surkhab Shelly
 
Input devices
Input devicesInput devices
Input devices
Surkhab Shelly
 
FUNCTIONAL UNIT
FUNCTIONAL UNITFUNCTIONAL UNIT
FUNCTIONAL UNIT
Surkhab Shelly
 
TYPES OF MEMORY
TYPES OF MEMORYTYPES OF MEMORY
TYPES OF MEMORY
Surkhab Shelly
 
cyber crime
 cyber crime cyber crime
cyber crime
Surkhab Shelly
 
Fun ppt
Fun pptFun ppt
Fun ppt
Surkhab Shelly
 
Dbms
DbmsDbms
Dbms
Surkhab Shelly
 
7 foods-to-keep you healthy
7 foods-to-keep  you healthy7 foods-to-keep  you healthy
7 foods-to-keep you healthy
Surkhab Shelly
 
Dbms ppt
Dbms pptDbms ppt
Dbms ppt
Surkhab Shelly
 
Ad

Recently uploaded (20)

π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
π0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalizationπ0.5: a Vision-Language-Action Model with Open-World Generalization
π0.5: a Vision-Language-Action Model with Open-World Generalization
NABLAS株式会社
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Ad

Avl tree ppt