SlideShare a Scribd company logo
1 of 46
AVL TREE
Name : Mahmudul Hasan
What
Why
How
AVL Tree
What is AVL tree ?
• AVL tree name after it’s
inventors
 Georgy Adelson
Velsky
 Evgenii Landis
Adelson
Velsky
Evgenii
Landis
• Normally it is a self-
balancing binary search
tree.
• In an AVL tree the height of
child subtree of any node
differ by at most one
WHY AVL Tree?
Advantage of AVL tree
• Better search times for keys
 the running time for a findKey(k) operation in a AVL tree is
guaranteed to be O(log(n))
Disadvantage of AVL tree
• Longer running time for insertion and deletion
 Every time insertion and deletion operation must
rebalance the avl tree
HOW ?
There are three type of operation in AVL tree
1.Insertion
2.Deletion
3.Searching
1. Insertion
For insertion we need to know about three things
those are
• Balance factor
• Rotation
 Right Rotation
 Left Rotation
• Case
 Right-Right
 Left-Left
 Left-Right
 Right-Left
Balance factor
T1 T2
B
Left Sub tree Right Sub Tree
H1 H2
Balance factor of B = Difference between left and right sub tree. [|H1-H2|}].
In AVL tree balance factor <=1.
Rotation
Left Rotation
R
X
T1
T3
T2
R
X
T1
T3
T2h
h
h+1
h h
h+1
Balance factor for R=|h-((h+1)+1)|=2
Balance factor for X=|h-(h+1)|=1
Left Rotation
Balance factor for R=|h-h|=0
Balance factor for X=|(h+1)-(h+1)|=0
Rotation
Right Rotation
R
X
T1
T3
T2
R
X
T2
T3
T1h
h
h+1
h h
h+1
Balance factor for R=|((h+1)+1)-h|=2
Balance factor for X=|(h+1)-h|=1
Right Rotation
Balance factor for R=|h-h|=0
Balance factor for X=|(h+1)-(h+1)|=0
Case:
Case 1: Right-Right.
Case 2: Left-Left.
Case 3: Right-Left
Case 4: Left-Right.
Case 1: Right-Right
When we Insert a node into right of a right sub tree of a node, unbalance may
be occur. For solving This case, we need to balance tree by rote unbalanced
node to left.
50
80
90
Rote left
50
80
90
For solving Right of Right imbalance
Case 2: Left-Left
When we Insert data into left of a left sub tree of a node, unbalance may be
occur. For solving This case, we need to balance tree by rote unbalanced
node to right.
50
30
20
20
30
50
For solving Left of Left imbalance
Rote right
Case 3: Right-Left
When we Insert data into left of a Right sub tree of a node, unbalance may be
occur. For solving This case, we need to balance tree using two steps. Given
below:
50
75
80
For solving Right-Left imbalance
50
80
75
Rote right
50
75
80
Rote left
Step 1 Step 2
Case 4: Left-Right
When we Insert data into Right of a left sub tree of a node, imbalance may be
occur. For solving This case, we need to balance tree using two steps. Given
below:
30
35
50
For solving Left of Right imbalance
Step 1 Step 2
50
30
35
50
35
30
Rote left
Rote right
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
500 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
500 (1,0)
400 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
500 (2,0)
400 (1,0)
300 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
500 (2,0)
400 (1,0)
300 (0,0)
L-L Case (root right)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (1,1)
300 (0,0) 500 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (1,2)
300 (0,0) 500 (0,1)
600 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (1,3)
300 (0,0) 500 (0,2)
600 (0,1)
700 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (1,3)
300 (0,0) 500 (0,2)
600 (0,1)
700 (0,0)
R-R case (Rote Left)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (1,2)
300 (0,0)
500
(1,1)600
(0,0)700(0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (2,2)
300 (1,0)
500
(1,1)600
(0,0)700(0,0)
200 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (3,2)
300 (2,0)
500
(1,1)600
(0,0)700(0,0)
200
250
(0,1)
(0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (3,2)
300 (2,0)
500
(1,1)600
(0,0)700(0,0)
200
250
(0,1)
(0,0)
L-R Case
Rote right
Step 2
Step 1
Rote left
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275, 260
400 (3,2)
300 (2,0)
500
(1,1)600
(0,0)700(0,0)
200
250
(0,0)
Rote right
Step 2
(1,0)
L-R Case
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250,275,260
400 (2,2)
300(0,0) 500
(1,1)600
(0,0)700(0,0)200
250
(0,0)
(1,1)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275 ,260
400 (3,2)
300(1,0) 500
(1,1)600
(0,0)700(0,0)200
250
(0,0)
(1,2)
275 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275 ,260
400 (4,2)
300(2,0) 500
(1,1)600
(0,0)700(0,0)200
250
(0,0)
(1,3)
275 (1,0)
260 (0,0)
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275 ,260
400 (4,2)
300(2,0) 500
(1,1)600
(0,0)700(0,0)200
250
(0,0)
(1,3)
275 (1,0)
260 (0,0)
Step 1: root right
L-L case
Inserting Example
Data: 500, 400, 300, 600, 700, 200, 250, 275 ,260
400 (3,2)
300
(1,1) 500
(1,1)600
(0,0)700(0,0)200
250
(0,0)
(1,2)
275
(0,0)260 (0,0)
Deletion
Case 1
• If we delete the leaf node than there will be no change in rest of
the tree
40 (3,2)
30
(0,0)
50
(1,1)60
70
(0,0)
25
27
(1,1) (0,0)
(1,1)
Deletion
Case 1
• If we delete the leaf node than there will be no change in rest of
the tree
40 (3,2)
30
(0,0)
50
(0,1)60
70
(0,0)
25
27
(1,1) (0,0)
(1,1)
Delete : 50
Deletion
Case 2
• We can delete internal node in two way
50 (2,1)
45
(0,0)
60
30
(1,1) 40
(0,0)
(0,0)
45 (2,1)
60
30
(1,0)40
(0,0)
(0,0)
Either
We can replaced it with it’s left subtree most bigger node
Deletion
Or
We can replaced it with it’s right subtree most smaller node
40
(2,2)
30
(0,0)
50
(1,1) 60
(0,0)
70
(0,0)
25
(1,1) 27
(0,0)
50
(2,2)
30
(0,0)
(1,1)60
70
(0,0)
25
(1,1)27
(0,0)
Deletion example
Data : 500, 400,300, 600, 700, 200, 250, 275 ,260
Delete :700
400 (3,2)
300
(1,1) 500
(1,1)600
(0,0)700(0,0)200
250
(0,0)
(1,2)
275
(0,0)260 (0,0)
Deletion example
Data : 500, 400,300, 600, 700, 200, 250, 275 ,260
Delete :700 ,250
400 (3,2)
300
(1,1) 500
(1,1)600
(0,0)700(0,0)200
250
(0,0)
(1,2)
275
(0,0)260 (0,0)
(1,0)
Deletion example
Data : 500, 400,300, 600, 700, 200, 250, 275 ,260
Delete :700 ,250
400 (3,2)
300
(1,1) 500
600
(0,0)200
250
(0,0)
(1,2)
275
(0,0)260 (0,0)
(1,0)
,400
(0,1)
Deletion example
Data : 500, 400,300, 600, 700, 200, 250, 275 ,260
Delete :700 ,250
400 (3,2)
300
(1,1) 500
600
(0,0)200
260
(0,0)
(1,2)
275
(0,0)
(1,0)
,400
(2,2)
(0,0)
Searching
• Searching for a specific key in an AVL tree can be done the same
way as binary search tree
400
500
600
700200
250
275
Search : 500
(500>400)
Searching
• Searching for a specific key in an AVL tree can be done the same
way as binary search tree
400
500
600
700200
250
275
Search : 500
(500>400)
(500<600)
Searching
• Searching for a specific key in an AVL tree can be done the same
way as binary search tree
400
500
600
700200
250
275
Search : 500
(500<600)
FOUND
(500=500)
References
 https://en.wikipedia.org/wiki/AVL_tree
 http://www.cise.ufl.edu/~nemo/cop3530/AVL-Tree-Rotations.pdf
 https://www.youtube.com/watch?v=YKt1kquKScY
 http://www.geeksforgeeks.org/avl-tree-set-1-insertion/
Thank you

More Related Content

More from Mahmudul Hasan

5 g architecture and application
5 g architecture and application5 g architecture and application
5 g architecture and applicationMahmudul Hasan
 
PLOTTING UNITE STEP AND RAMP FUNCTION IN MATLAB
PLOTTING UNITE STEP AND RAMP  FUNCTION  IN  MATLAB PLOTTING UNITE STEP AND RAMP  FUNCTION  IN  MATLAB
PLOTTING UNITE STEP AND RAMP FUNCTION IN MATLAB Mahmudul Hasan
 
Design pipeline architecture for various stage pipelines
Design pipeline architecture for various stage pipelinesDesign pipeline architecture for various stage pipelines
Design pipeline architecture for various stage pipelinesMahmudul Hasan
 
Elimination of left recursion
Elimination of left recursionElimination of left recursion
Elimination of left recursionMahmudul Hasan
 
গুড়পুকুরের মেলা
গুড়পুকুরের মেলাগুড়পুকুরের মেলা
গুড়পুকুরের মেলাMahmudul Hasan
 
Emergency system AI presentation Using Prolog
Emergency system AI presentation Using PrologEmergency system AI presentation Using Prolog
Emergency system AI presentation Using PrologMahmudul Hasan
 
Bank management system
Bank management systemBank management system
Bank management systemMahmudul Hasan
 
Hospital management system DBMS PROJECT USING APEX 5.04
Hospital management system DBMS PROJECT USING APEX 5.04Hospital management system DBMS PROJECT USING APEX 5.04
Hospital management system DBMS PROJECT USING APEX 5.04Mahmudul Hasan
 

More from Mahmudul Hasan (14)

C Programming Loop
C Programming LoopC Programming Loop
C Programming Loop
 
E commerce Website
E commerce WebsiteE commerce Website
E commerce Website
 
5 g architecture and application
5 g architecture and application5 g architecture and application
5 g architecture and application
 
Car parking system
Car parking systemCar parking system
Car parking system
 
Software company
Software companySoftware company
Software company
 
PLOTTING UNITE STEP AND RAMP FUNCTION IN MATLAB
PLOTTING UNITE STEP AND RAMP  FUNCTION  IN  MATLAB PLOTTING UNITE STEP AND RAMP  FUNCTION  IN  MATLAB
PLOTTING UNITE STEP AND RAMP FUNCTION IN MATLAB
 
Design pipeline architecture for various stage pipelines
Design pipeline architecture for various stage pipelinesDesign pipeline architecture for various stage pipelines
Design pipeline architecture for various stage pipelines
 
Elimination of left recursion
Elimination of left recursionElimination of left recursion
Elimination of left recursion
 
2 bit alu
2 bit alu2 bit alu
2 bit alu
 
গুড়পুকুরের মেলা
গুড়পুকুরের মেলাগুড়পুকুরের মেলা
গুড়পুকুরের মেলা
 
Emergency system AI presentation Using Prolog
Emergency system AI presentation Using PrologEmergency system AI presentation Using Prolog
Emergency system AI presentation Using Prolog
 
Bank management system
Bank management systemBank management system
Bank management system
 
Hospital management system DBMS PROJECT USING APEX 5.04
Hospital management system DBMS PROJECT USING APEX 5.04Hospital management system DBMS PROJECT USING APEX 5.04
Hospital management system DBMS PROJECT USING APEX 5.04
 
Digital search tree
Digital search treeDigital search tree
Digital search tree
 

Recently uploaded

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

Avl tree

  • 4. What is AVL tree ? • AVL tree name after it’s inventors  Georgy Adelson Velsky  Evgenii Landis Adelson Velsky Evgenii Landis • Normally it is a self- balancing binary search tree. • In an AVL tree the height of child subtree of any node differ by at most one
  • 5. WHY AVL Tree? Advantage of AVL tree • Better search times for keys  the running time for a findKey(k) operation in a AVL tree is guaranteed to be O(log(n)) Disadvantage of AVL tree • Longer running time for insertion and deletion  Every time insertion and deletion operation must rebalance the avl tree
  • 6. HOW ? There are three type of operation in AVL tree 1.Insertion 2.Deletion 3.Searching
  • 7. 1. Insertion For insertion we need to know about three things those are • Balance factor • Rotation  Right Rotation  Left Rotation • Case  Right-Right  Left-Left  Left-Right  Right-Left
  • 8. Balance factor T1 T2 B Left Sub tree Right Sub Tree H1 H2 Balance factor of B = Difference between left and right sub tree. [|H1-H2|}]. In AVL tree balance factor <=1.
  • 9. Rotation Left Rotation R X T1 T3 T2 R X T1 T3 T2h h h+1 h h h+1 Balance factor for R=|h-((h+1)+1)|=2 Balance factor for X=|h-(h+1)|=1 Left Rotation Balance factor for R=|h-h|=0 Balance factor for X=|(h+1)-(h+1)|=0
  • 10. Rotation Right Rotation R X T1 T3 T2 R X T2 T3 T1h h h+1 h h h+1 Balance factor for R=|((h+1)+1)-h|=2 Balance factor for X=|(h+1)-h|=1 Right Rotation Balance factor for R=|h-h|=0 Balance factor for X=|(h+1)-(h+1)|=0
  • 11. Case: Case 1: Right-Right. Case 2: Left-Left. Case 3: Right-Left Case 4: Left-Right.
  • 12. Case 1: Right-Right When we Insert a node into right of a right sub tree of a node, unbalance may be occur. For solving This case, we need to balance tree by rote unbalanced node to left. 50 80 90 Rote left 50 80 90 For solving Right of Right imbalance
  • 13. Case 2: Left-Left When we Insert data into left of a left sub tree of a node, unbalance may be occur. For solving This case, we need to balance tree by rote unbalanced node to right. 50 30 20 20 30 50 For solving Left of Left imbalance Rote right
  • 14. Case 3: Right-Left When we Insert data into left of a Right sub tree of a node, unbalance may be occur. For solving This case, we need to balance tree using two steps. Given below: 50 75 80 For solving Right-Left imbalance 50 80 75 Rote right 50 75 80 Rote left Step 1 Step 2
  • 15. Case 4: Left-Right When we Insert data into Right of a left sub tree of a node, imbalance may be occur. For solving This case, we need to balance tree using two steps. Given below: 30 35 50 For solving Left of Right imbalance Step 1 Step 2 50 30 35 50 35 30 Rote left Rote right
  • 16. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 500 (0,0)
  • 17. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 500 (1,0) 400 (0,0)
  • 18. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 500 (2,0) 400 (1,0) 300 (0,0)
  • 19. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 500 (2,0) 400 (1,0) 300 (0,0) L-L Case (root right)
  • 20. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (1,1) 300 (0,0) 500 (0,0)
  • 21. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (1,2) 300 (0,0) 500 (0,1) 600 (0,0)
  • 22. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (1,3) 300 (0,0) 500 (0,2) 600 (0,1) 700 (0,0)
  • 23. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (1,3) 300 (0,0) 500 (0,2) 600 (0,1) 700 (0,0) R-R case (Rote Left)
  • 24. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (1,2) 300 (0,0) 500 (1,1)600 (0,0)700(0,0)
  • 25. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (2,2) 300 (1,0) 500 (1,1)600 (0,0)700(0,0) 200 (0,0)
  • 26. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (3,2) 300 (2,0) 500 (1,1)600 (0,0)700(0,0) 200 250 (0,1) (0,0)
  • 27. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (3,2) 300 (2,0) 500 (1,1)600 (0,0)700(0,0) 200 250 (0,1) (0,0) L-R Case Rote right Step 2 Step 1 Rote left
  • 28. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275, 260 400 (3,2) 300 (2,0) 500 (1,1)600 (0,0)700(0,0) 200 250 (0,0) Rote right Step 2 (1,0) L-R Case
  • 29. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250,275,260 400 (2,2) 300(0,0) 500 (1,1)600 (0,0)700(0,0)200 250 (0,0) (1,1)
  • 30. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275 ,260 400 (3,2) 300(1,0) 500 (1,1)600 (0,0)700(0,0)200 250 (0,0) (1,2) 275 (0,0)
  • 31. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275 ,260 400 (4,2) 300(2,0) 500 (1,1)600 (0,0)700(0,0)200 250 (0,0) (1,3) 275 (1,0) 260 (0,0)
  • 32. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275 ,260 400 (4,2) 300(2,0) 500 (1,1)600 (0,0)700(0,0)200 250 (0,0) (1,3) 275 (1,0) 260 (0,0) Step 1: root right L-L case
  • 33. Inserting Example Data: 500, 400, 300, 600, 700, 200, 250, 275 ,260 400 (3,2) 300 (1,1) 500 (1,1)600 (0,0)700(0,0)200 250 (0,0) (1,2) 275 (0,0)260 (0,0)
  • 34. Deletion Case 1 • If we delete the leaf node than there will be no change in rest of the tree 40 (3,2) 30 (0,0) 50 (1,1)60 70 (0,0) 25 27 (1,1) (0,0) (1,1)
  • 35. Deletion Case 1 • If we delete the leaf node than there will be no change in rest of the tree 40 (3,2) 30 (0,0) 50 (0,1)60 70 (0,0) 25 27 (1,1) (0,0) (1,1) Delete : 50
  • 36. Deletion Case 2 • We can delete internal node in two way 50 (2,1) 45 (0,0) 60 30 (1,1) 40 (0,0) (0,0) 45 (2,1) 60 30 (1,0)40 (0,0) (0,0) Either We can replaced it with it’s left subtree most bigger node
  • 37. Deletion Or We can replaced it with it’s right subtree most smaller node 40 (2,2) 30 (0,0) 50 (1,1) 60 (0,0) 70 (0,0) 25 (1,1) 27 (0,0) 50 (2,2) 30 (0,0) (1,1)60 70 (0,0) 25 (1,1)27 (0,0)
  • 38. Deletion example Data : 500, 400,300, 600, 700, 200, 250, 275 ,260 Delete :700 400 (3,2) 300 (1,1) 500 (1,1)600 (0,0)700(0,0)200 250 (0,0) (1,2) 275 (0,0)260 (0,0)
  • 39. Deletion example Data : 500, 400,300, 600, 700, 200, 250, 275 ,260 Delete :700 ,250 400 (3,2) 300 (1,1) 500 (1,1)600 (0,0)700(0,0)200 250 (0,0) (1,2) 275 (0,0)260 (0,0) (1,0)
  • 40. Deletion example Data : 500, 400,300, 600, 700, 200, 250, 275 ,260 Delete :700 ,250 400 (3,2) 300 (1,1) 500 600 (0,0)200 250 (0,0) (1,2) 275 (0,0)260 (0,0) (1,0) ,400 (0,1)
  • 41. Deletion example Data : 500, 400,300, 600, 700, 200, 250, 275 ,260 Delete :700 ,250 400 (3,2) 300 (1,1) 500 600 (0,0)200 260 (0,0) (1,2) 275 (0,0) (1,0) ,400 (2,2) (0,0)
  • 42. Searching • Searching for a specific key in an AVL tree can be done the same way as binary search tree 400 500 600 700200 250 275 Search : 500 (500>400)
  • 43. Searching • Searching for a specific key in an AVL tree can be done the same way as binary search tree 400 500 600 700200 250 275 Search : 500 (500>400) (500<600)
  • 44. Searching • Searching for a specific key in an AVL tree can be done the same way as binary search tree 400 500 600 700200 250 275 Search : 500 (500<600) FOUND (500=500)
  • 45. References  https://en.wikipedia.org/wiki/AVL_tree  http://www.cise.ufl.edu/~nemo/cop3530/AVL-Tree-Rotations.pdf  https://www.youtube.com/watch?v=YKt1kquKScY  http://www.geeksforgeeks.org/avl-tree-set-1-insertion/