SlideShare a Scribd company logo
1 of 43
 First-invented self-balancing binary
search tree
 Named after its two inventors,
1. G.M. Adelson-Velsky and
2. E.M. Landis,
› published it in their 1962 paper "An
algorithm for the organization of
information."
 First, its a binary search tree...
 L <= P and P <= R
RL
P
 Is this a binary tree search tree?
3 9
5
15 21
17
28 34
32
43 51
46
52 54
53
58 68
60 71 79
7712 35 56
29 70
50
 An AVL tree is a balanced binary tree
 To understand balance we need to
understand the notion of Tree Height
55
32 71
64 86 Height 0
Height 1
Height 2
 By default, nodes with no children have
a height of Height of 0.
55
32 71
64 86 Height 0
Height 1
Height 2
Height
0
Height 0
 But, we must also understand the
concept of Sub-trees
55
32 71
64 86
Height 0 Height 1
Height 2
Height 0 Height 0
sub-tree L has a
height of 0 sub-tree R has a
height of 1
Height = max(L.height, R.height) + 1
 Also empty sub-trees have a Height of -1
44
58
91
Height = 2 = max(0, 1) + 1
Height = 0 = max(-1,-1) + 1
Height = max(L.height, R.height) + 1
Height = 1 = max(-1, 0) + 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
1.. heightRheightL
1. After every insertion
2. Check to see if an imbalance was
created.
• All you have to do backtrack up the tree
3. If you 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
14
15
• First insert 14 and
15:
• Now insert 16.
Single rotations:
14
15
• Inserting 16 causes AVL violation:
• Need to rotate.
16
Single rotations:
14
15
• Rotation type:
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 insert 11.
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 insert 10.
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 insert 3.
• 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
12
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 insert 4.
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 insert 5.
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
15
2
111 4
5 12 14 16
3
• AVL violation –
rotate.
7
Single rotations:
10
13
15
2
111 4
5 12 14 16
3
7
• Rotation type:
Double rotations:
10
13
15
4
112 5
7 12 14 16
31
• AVL violation -
rotate.
6
Double rotations:
10
13
15
4
112 5
7 12 14 16
31
• Rotation type:
6
Double rotations:
10
13
15
4
112 6
7
12 14 16
31
• AVL balance
restored.
• Now insert 9 and 8.
5
Double rotations:
10
13
15
4
112 6
7
12 14 16
31
• Rotation type:
9
8
5
Final tree:
10
13
15
4
112 6
8
12 14 16
31
• Tree is almost perfectly
balanced
5
97

More Related Content

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Avl trees