SlideShare a Scribd company logo
1 of 20
Advanced Data StructuresMphil AVL Trees Jibrael Jos : Nov2009
AVL Rotate Right / Left Simple Double Complex Rotate Rotate Algo Double Rotate Avoid Taking Printout : Use RTF Outline in case needed 2 Agenda
AVL Trees 1962 – Two Russian Mathematicians Adelson-Velskii  and Landis Heights of Subtree do not defer by more than one Avoid Taking Printout : Use RTF Outline in case needed 3
AVL Trees - Why Avoid Taking Printout : Use RTF Outline in case needed 4 18 14 Unbalanced  BST Tree 12 8 8 12 4 4 14 18 AVL
AVL – Rotate Right Please Do Not Take Printout : Use RTF Outline in case needed 5 12 8 4
AVL – Rotate Left Please Do Not Take Printout : Use RTF Outline in case needed 6 4 8 12
Complex Right Please Do Not Take Printout : Use RTF Outline in case needed 7 18 20 12 8 14 4
Complex Left Please Do Not Take Printout : Use RTF Outline in case needed 8 8 14 4 18 12 20
Complex Right - Algo Please Do Not Take Printout : Use RTF Outline in case needed 9 18 Root Result Should Be 12 tempPtr 12 18 8 8 14 14
Complex Right - Algo Please Do Not Take Printout : Use RTF Outline in case needed 10 tempPtr = root -> left Root -> left = tempPtr -> right tempPtr -> right = root Root = tempPtr return 18 Root 12 tempPtr 8 14
Simple Double Rotate Right Please Do Not Take Printout : Use RTF Outline in case needed 11 12 4 Step 1 :  8
Simple Double Rotate Right Please Do Not Take Printout : Use RTF Outline in case needed 12 12 8 Step 2 :  4
AVL Node Node Key Data left Right Bal (RH , LH , EH) End Node Avoid Taking Printout : Use RTF Outline in case needed 13
AVL Insert / Transcript In linked list we did search and then insert But here we need to adjust balance and may have to adjust tree not only at the point of  insertion but all the way up We set taller flag Let prev module decide as we back out of recursions Avoid Taking Printout : Use RTF Outline in case needed 14
AVL Insert Please Do Not Take Printout : Use RTF Outline in case needed 15 60 50 EH Other Node already inserted 13 EH 18 LH 12 20 EH EH 8 14 EH EH Different stages of a node visit ?
Flow Chart Please Do Not Take Printout : Use RTF Outline in case needed 16 Recursion If tree is taller If LH and we inserted on left Yes Yes Balance No No Yes If RH and we inserted on right
AVL INSERT ALGO If root is null        Taller = true        Root = newPtr else    If insert on left “ < “          AVL Insert (root -> left)         if taller              if  LH do left balance             else if root is RH                     taller=false             adjust balance factor Avoid Taking Printout : Use RTF Outline in case needed 17 When will it not be taller ?
AVL left Balance leftTree= root - >left If leftTree is LH             Case 1: left of left : single rotate Else Case 2: right of left : Double Rotation rightTree=leftTree->right Adjust balance for Right Tree rotateLeft(leftTree) rotateRight(root) Taller = false return Avoid Taking Printout : Use RTF Outline in case needed 18
Flow Please Do Not Take Printout : Use RTF Outline in case needed 19
Reference My Course Furzon Please Do Not Take Printout : Use RTF Outline in case needed 20 Action Item ,[object Object]

More Related Content

What's hot

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 StructureYaksh Jethva
 
Red black trees and their properties
Red black trees and their propertiesRed black trees and their properties
Red black trees and their propertiesKousalya M
 
THREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREETHREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREESiddhi Shrivas
 
Application of tries
Application of triesApplication of tries
Application of triesTech_MX
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree dsViji B
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Oum Saokosal
 
Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsortSsankett Negi
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....Shail Nakum
 
Memory Segmentation of 8086
Memory Segmentation of 8086Memory Segmentation of 8086
Memory Segmentation of 8086Nikhil Kumar
 
Parity check(Error Detecting Codes)
Parity check(Error Detecting Codes)Parity check(Error Detecting Codes)
Parity check(Error Detecting Codes)Imesha Perera
 
PAI Unit 3 Paging in 80386 Microporcessor
PAI Unit 3 Paging in 80386 MicroporcessorPAI Unit 3 Paging in 80386 Microporcessor
PAI Unit 3 Paging in 80386 MicroporcessorKanchanPatil34
 
8259 Interrupt Controller
8259 Interrupt Controller8259 Interrupt Controller
8259 Interrupt ControllerShivamSood22
 

What's hot (20)

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
 
Hamming code checksum
Hamming code  checksumHamming code  checksum
Hamming code checksum
 
Icmp
IcmpIcmp
Icmp
 
Red black trees and their properties
Red black trees and their propertiesRed black trees and their properties
Red black trees and their properties
 
THREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREETHREADED BINARY TREE AND BINARY SEARCH TREE
THREADED BINARY TREE AND BINARY SEARCH TREE
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
 
Application of tries
Application of triesApplication of tries
Application of tries
 
2 3 tree
2 3 tree2 3 tree
2 3 tree
 
Introduction to tree ds
Introduction to tree dsIntroduction to tree ds
Introduction to tree ds
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
Avl trees
Avl treesAvl trees
Avl trees
 
Trees
TreesTrees
Trees
 
Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsort
 
Avl trees
Avl treesAvl trees
Avl trees
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
 
Memory Segmentation of 8086
Memory Segmentation of 8086Memory Segmentation of 8086
Memory Segmentation of 8086
 
Parity check(Error Detecting Codes)
Parity check(Error Detecting Codes)Parity check(Error Detecting Codes)
Parity check(Error Detecting Codes)
 
PAI Unit 3 Paging in 80386 Microporcessor
PAI Unit 3 Paging in 80386 MicroporcessorPAI Unit 3 Paging in 80386 Microporcessor
PAI Unit 3 Paging in 80386 Microporcessor
 
8259 Interrupt Controller
8259 Interrupt Controller8259 Interrupt Controller
8259 Interrupt Controller
 
Avl tree
Avl treeAvl tree
Avl tree
 

Viewers also liked (10)

Avl trees
Avl treesAvl trees
Avl trees
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Avl trees
Avl treesAvl trees
Avl trees
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVL
 
Avl tree
Avl treeAvl tree
Avl tree
 
Binary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red BlackBinary Search Trees - AVL and Red Black
Binary Search Trees - AVL and Red Black
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Binary tree
Binary  treeBinary  tree
Binary tree
 

More from Jibrael Jos

Followership, A Leadership Workshop
Followership, A Leadership WorkshopFollowership, A Leadership Workshop
Followership, A Leadership WorkshopJibrael Jos
 
Steven Covey 7 Habits of Highly Effective People
Steven Covey 7 Habits of Highly Effective PeopleSteven Covey 7 Habits of Highly Effective People
Steven Covey 7 Habits of Highly Effective PeopleJibrael Jos
 
Big Bang to DNA , Relatively Speaking
Big Bang to DNA , Relatively SpeakingBig Bang to DNA , Relatively Speaking
Big Bang to DNA , Relatively SpeakingJibrael Jos
 
Data Structures : Sort Explained
Data Structures : Sort ExplainedData Structures : Sort Explained
Data Structures : Sort ExplainedJibrael Jos
 
Data Structures : Sorting
Data Structures : SortingData Structures : Sorting
Data Structures : SortingJibrael Jos
 
Data Structures, Graphs
Data Structures, GraphsData Structures, Graphs
Data Structures, GraphsJibrael Jos
 
BTree, Data Structures
BTree, Data StructuresBTree, Data Structures
BTree, Data StructuresJibrael Jos
 

More from Jibrael Jos (7)

Followership, A Leadership Workshop
Followership, A Leadership WorkshopFollowership, A Leadership Workshop
Followership, A Leadership Workshop
 
Steven Covey 7 Habits of Highly Effective People
Steven Covey 7 Habits of Highly Effective PeopleSteven Covey 7 Habits of Highly Effective People
Steven Covey 7 Habits of Highly Effective People
 
Big Bang to DNA , Relatively Speaking
Big Bang to DNA , Relatively SpeakingBig Bang to DNA , Relatively Speaking
Big Bang to DNA , Relatively Speaking
 
Data Structures : Sort Explained
Data Structures : Sort ExplainedData Structures : Sort Explained
Data Structures : Sort Explained
 
Data Structures : Sorting
Data Structures : SortingData Structures : Sorting
Data Structures : Sorting
 
Data Structures, Graphs
Data Structures, GraphsData Structures, Graphs
Data Structures, Graphs
 
BTree, Data Structures
BTree, Data StructuresBTree, Data Structures
BTree, Data Structures
 

Recently uploaded

Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 

Recently uploaded (20)

Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 

Data Structures : AVL Trees

  • 1. Advanced Data StructuresMphil AVL Trees Jibrael Jos : Nov2009
  • 2. AVL Rotate Right / Left Simple Double Complex Rotate Rotate Algo Double Rotate Avoid Taking Printout : Use RTF Outline in case needed 2 Agenda
  • 3. AVL Trees 1962 – Two Russian Mathematicians Adelson-Velskii and Landis Heights of Subtree do not defer by more than one Avoid Taking Printout : Use RTF Outline in case needed 3
  • 4. AVL Trees - Why Avoid Taking Printout : Use RTF Outline in case needed 4 18 14 Unbalanced BST Tree 12 8 8 12 4 4 14 18 AVL
  • 5. AVL – Rotate Right Please Do Not Take Printout : Use RTF Outline in case needed 5 12 8 4
  • 6. AVL – Rotate Left Please Do Not Take Printout : Use RTF Outline in case needed 6 4 8 12
  • 7. Complex Right Please Do Not Take Printout : Use RTF Outline in case needed 7 18 20 12 8 14 4
  • 8. Complex Left Please Do Not Take Printout : Use RTF Outline in case needed 8 8 14 4 18 12 20
  • 9. Complex Right - Algo Please Do Not Take Printout : Use RTF Outline in case needed 9 18 Root Result Should Be 12 tempPtr 12 18 8 8 14 14
  • 10. Complex Right - Algo Please Do Not Take Printout : Use RTF Outline in case needed 10 tempPtr = root -> left Root -> left = tempPtr -> right tempPtr -> right = root Root = tempPtr return 18 Root 12 tempPtr 8 14
  • 11. Simple Double Rotate Right Please Do Not Take Printout : Use RTF Outline in case needed 11 12 4 Step 1 : 8
  • 12. Simple Double Rotate Right Please Do Not Take Printout : Use RTF Outline in case needed 12 12 8 Step 2 : 4
  • 13. AVL Node Node Key Data left Right Bal (RH , LH , EH) End Node Avoid Taking Printout : Use RTF Outline in case needed 13
  • 14. AVL Insert / Transcript In linked list we did search and then insert But here we need to adjust balance and may have to adjust tree not only at the point of insertion but all the way up We set taller flag Let prev module decide as we back out of recursions Avoid Taking Printout : Use RTF Outline in case needed 14
  • 15. AVL Insert Please Do Not Take Printout : Use RTF Outline in case needed 15 60 50 EH Other Node already inserted 13 EH 18 LH 12 20 EH EH 8 14 EH EH Different stages of a node visit ?
  • 16. Flow Chart Please Do Not Take Printout : Use RTF Outline in case needed 16 Recursion If tree is taller If LH and we inserted on left Yes Yes Balance No No Yes If RH and we inserted on right
  • 17. AVL INSERT ALGO If root is null Taller = true Root = newPtr else If insert on left “ < “ AVL Insert (root -> left) if taller if LH do left balance else if root is RH taller=false adjust balance factor Avoid Taking Printout : Use RTF Outline in case needed 17 When will it not be taller ?
  • 18. AVL left Balance leftTree= root - >left If leftTree is LH Case 1: left of left : single rotate Else Case 2: right of left : Double Rotation rightTree=leftTree->right Adjust balance for Right Tree rotateLeft(leftTree) rotateRight(root) Taller = false return Avoid Taking Printout : Use RTF Outline in case needed 18
  • 19. Flow Please Do Not Take Printout : Use RTF Outline in case needed 19
  • 20.