SlideShare a Scribd company logo
1 of 16
AVL trees
AVL Trees
We have seen that all operations depend on the depth of
the tree.
We don’t want trees with nodes which have large height
This can be attained if both subtrees of each node have
roughly the same height.
AVL tree is a binary search tree where the height of the
two subtrees of a node differs by at most one
Height of a null tree is -1
5
3 8
1 4 10
5
3
1 4
AVL Tree
Not AVL Tree
Section 10.4 KR
Suppose an AVL tree of height h contains
contains at most S(h) nodes:
S(h) = L(h) + R(h) + 1
L(h) is the number of nodes in left subtree
R(h) is the number of nodes in right subtree
You have larger number of nodes if there is larger
imbalance between the subtrees
This happens if one subtree has height h, another h-2
Thus, S(h) = S(h) + S(h-2) + 1
Operations in AVL Tree
Searching, Complexity?
FindMin, Complexity?
Deletion? Insertion?
O(log N)
O(log N)
Insertion
Search for the element
If it is not there, insert it in its place.
Any problem?
Insertion may imbalance the tree. Heights of two
children of a node may differ by 2 after an
insertion.
Tree Rotations used to restore the balance.
If an insertion cause an imbalance, which nodes can be
affected?
Nodes on the path of the inserted node.
Let U be the node nearest to the inserted one which has an imbalance.
insertion in the left subtree of the left child of U
insertion in the right subtree of the left child of U
insertion in the left subtree of the right child of U
insertion in the right subtree of the right child of U
Insertion in left child of left
subtree
Single Rotation
U
V
X
Y
Z
V
U
X
Y Z
Before Rotation
After Rotation
5
3
1 4
Insert 0.8
AVL Tree
8
0.8
5
3
1 4
8
U
V
X
Y
Z
3
5
1
0.8
4 8
After Rotation
Double Rotation
Suppose, imbalance is due to an insertion in the left subtree of
right child
Single Rotation does not work!
U
V
A
D
W
B C
W
V U
A D
B C
Before Rotation
After Rotation
5
3
1 4
Insert 3.5
AVL Tree
8
3.5
5
3
1 4
8
4
5
0.8
3
3.5
After Rotation
U
V
A W
B
D
8
Extended Example
Insert 3,2,1,4,5,6,7, 16,15,14
3
Fig 1
3
2
Fig 2
3
2
1
Fig 3
2
1
3
Fig 4
2
1
3
4
Fig 5
2
1
3
4
5
Fig 6
2
1
4
5
3
Fig 7 6
2
1
4
5
3
Fig 8
4
2
5
6
1 3
Fig 9
4
2
5
6
1 3
7
Fig 10
4
2
6
7
1 3
5 Fig 11
4
2
6
7
1 3
5 16
Fig 12
4
2
6
7
1 3
5 16
15
Fig 13
4
2
6
15
1 3 5
16
7
Fig 14
5
4
2 7
15
1 3 6
16
14
Fig 16
4
2
6
15
1 3 5
16
7
14
Fig 15
Deletions can be done with similar rotations
Using this you can show that h = O(log N)
Rings a bell! Fibonacci numbers
FN N
S(h) h
h is O(log N)

More Related Content

Similar to avltrees.ppt unit 4 ppts for the university exam

Study about AVL Tree & Operations
Study about AVL Tree & OperationsStudy about AVL Tree & Operations
Study about AVL Tree & OperationsEditor IJCTER
 
Design data Analysis Avl Trees.pptx by piyush sir
Design data Analysis Avl Trees.pptx by piyush sirDesign data Analysis Avl Trees.pptx by piyush sir
Design data Analysis Avl Trees.pptx by piyush sir22001003058
 
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
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesManishPrajapati78
 
AVL Trees.pptx DATA STRUCTURES AND ALGORITHMS
AVL Trees.pptx DATA STRUCTURES AND ALGORITHMSAVL Trees.pptx DATA STRUCTURES AND ALGORITHMS
AVL Trees.pptx DATA STRUCTURES AND ALGORITHMSAnyaForger34
 
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.pptxMalligaarjunanN
 
Adelson velskii Landis rotations based on
Adelson velskii Landis rotations based onAdelson velskii Landis rotations based on
Adelson velskii Landis rotations based onbanupriyar5
 
avl insertion-rotation
avl insertion-rotationavl insertion-rotation
avl insertion-rotationXad Kuain
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20ecomputernotes
 
AVL_Trees using DSA concepts and how to do
AVL_Trees using DSA concepts and how to doAVL_Trees using DSA concepts and how to do
AVL_Trees using DSA concepts and how to dolokaprasaadvs
 
Review session2
Review session2Review session2
Review session2NEEDY12345
 
Computer notes - AVL Tree
Computer notes - AVL TreeComputer notes - AVL Tree
Computer notes - AVL Treeecomputernotes
 

Similar to avltrees.ppt unit 4 ppts for the university exam (20)

Study about AVL Tree & Operations
Study about AVL Tree & OperationsStudy about AVL Tree & Operations
Study about AVL Tree & Operations
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
AVL tree PPT.pptx
AVL tree PPT.pptxAVL tree PPT.pptx
AVL tree PPT.pptx
 
Design data Analysis Avl Trees.pptx by piyush sir
Design data Analysis Avl Trees.pptx by piyush sirDesign data Analysis Avl Trees.pptx by piyush sir
Design data Analysis Avl Trees.pptx by piyush sir
 
Avltrees
AvltreesAvltrees
Avltrees
 
Avl tree ppt
Avl tree pptAvl tree ppt
Avl tree ppt
 
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
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
 
DS_Mod4_2.pdf
DS_Mod4_2.pdfDS_Mod4_2.pdf
DS_Mod4_2.pdf
 
AVL Trees.pptx DATA STRUCTURES AND ALGORITHMS
AVL Trees.pptx DATA STRUCTURES AND ALGORITHMSAVL Trees.pptx DATA STRUCTURES AND ALGORITHMS
AVL Trees.pptx DATA STRUCTURES AND ALGORITHMS
 
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
 
Avl tree
Avl treeAvl tree
Avl tree
 
Adelson velskii Landis rotations based on
Adelson velskii Landis rotations based onAdelson velskii Landis rotations based on
Adelson velskii Landis rotations based on
 
avl insertion-rotation
avl insertion-rotationavl insertion-rotation
avl insertion-rotation
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
 
AVL_Trees using DSA concepts and how to do
AVL_Trees using DSA concepts and how to doAVL_Trees using DSA concepts and how to do
AVL_Trees using DSA concepts and how to do
 
Review session2
Review session2Review session2
Review session2
 
AVL-TREE.ppt
AVL-TREE.pptAVL-TREE.ppt
AVL-TREE.ppt
 
Computer notes - AVL Tree
Computer notes - AVL TreeComputer notes - AVL Tree
Computer notes - AVL Tree
 

More from RAtna29

PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnPatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnRAtna29
 
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnNLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnRAtna29
 
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbLexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbRAtna29
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt tttttttttttttttttttttttttttttRAtna29
 
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzlecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzRAtna29
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmRAtna29
 
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNModel-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNRAtna29
 
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyTF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyRAtna29
 
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhexing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhRAtna29
 
redblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxredblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxRAtna29
 
btree.ppt ggggggggggggggggggggggggggggggg
btree.ppt gggggggggggggggggggggggggggggggbtree.ppt ggggggggggggggggggggggggggggggg
btree.ppt gggggggggggggggggggggggggggggggRAtna29
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbRAtna29
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuavltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuRAtna29
 
nlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmnlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmRAtna29
 

More from RAtna29 (15)

PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnPatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
PatternMatching2.pptnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnNLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
NLP-ppt.pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbbLexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
Lexical-Semantics-NLP.pptx bbbbbbbbbbbbbbb
 
btrees.ppt ttttttttttttttttttttttttttttt
btrees.ppt  tttttttttttttttttttttttttttttbtrees.ppt  ttttttttttttttttttttttttttttt
btrees.ppt ttttttttttttttttttttttttttttt
 
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzlecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
lecture09.ppt zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
 
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmmIndexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
Indexing.ppt mmmmmmmmmmmmmmmmmmmmmmmmmmmmm
 
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNNModel-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
Model-Theoretic Semantics.pdf NNNNNNNNNNNNNNNNNNNNN
 
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyTF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
TF-IDF.pdf yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
 
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhexing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
exing.ppt hhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
redblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptxredblacktreeindatastructure-200409083949.pptx
redblacktreeindatastructure-200409083949.pptx
 
btree.ppt ggggggggggggggggggggggggggggggg
btree.ppt gggggggggggggggggggggggggggggggbtree.ppt ggggggggggggggggggggggggggggggg
btree.ppt ggggggggggggggggggggggggggggggg
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuavltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
 
nlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmmnlp semantic for parsing ... mmmmmmmmmmmm
nlp semantic for parsing ... mmmmmmmmmmmm
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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
 
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
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
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
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
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
 
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
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.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 ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
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
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

avltrees.ppt unit 4 ppts for the university exam

  • 2. AVL Trees We have seen that all operations depend on the depth of the tree. We don’t want trees with nodes which have large height This can be attained if both subtrees of each node have roughly the same height. AVL tree is a binary search tree where the height of the two subtrees of a node differs by at most one Height of a null tree is -1
  • 3. 5 3 8 1 4 10 5 3 1 4 AVL Tree Not AVL Tree
  • 4. Section 10.4 KR Suppose an AVL tree of height h contains contains at most S(h) nodes: S(h) = L(h) + R(h) + 1 L(h) is the number of nodes in left subtree R(h) is the number of nodes in right subtree You have larger number of nodes if there is larger imbalance between the subtrees This happens if one subtree has height h, another h-2 Thus, S(h) = S(h) + S(h-2) + 1
  • 5. Operations in AVL Tree Searching, Complexity? FindMin, Complexity? Deletion? Insertion? O(log N) O(log N)
  • 6. Insertion Search for the element If it is not there, insert it in its place. Any problem? Insertion may imbalance the tree. Heights of two children of a node may differ by 2 after an insertion. Tree Rotations used to restore the balance.
  • 7. If an insertion cause an imbalance, which nodes can be affected? Nodes on the path of the inserted node. Let U be the node nearest to the inserted one which has an imbalance. insertion in the left subtree of the left child of U insertion in the right subtree of the left child of U insertion in the left subtree of the right child of U insertion in the right subtree of the right child of U
  • 8. Insertion in left child of left subtree Single Rotation U V X Y Z V U X Y Z Before Rotation After Rotation
  • 9. 5 3 1 4 Insert 0.8 AVL Tree 8 0.8 5 3 1 4 8 U V X Y Z 3 5 1 0.8 4 8 After Rotation
  • 10. Double Rotation Suppose, imbalance is due to an insertion in the left subtree of right child Single Rotation does not work! U V A D W B C W V U A D B C Before Rotation After Rotation
  • 11. 5 3 1 4 Insert 3.5 AVL Tree 8 3.5 5 3 1 4 8 4 5 0.8 3 3.5 After Rotation U V A W B D 8
  • 12. Extended Example Insert 3,2,1,4,5,6,7, 16,15,14 3 Fig 1 3 2 Fig 2 3 2 1 Fig 3 2 1 3 Fig 4 2 1 3 4 Fig 5 2 1 3 4 5 Fig 6
  • 13. 2 1 4 5 3 Fig 7 6 2 1 4 5 3 Fig 8 4 2 5 6 1 3 Fig 9 4 2 5 6 1 3 7 Fig 10 4 2 6 7 1 3 5 Fig 11
  • 14. 4 2 6 7 1 3 5 16 Fig 12 4 2 6 7 1 3 5 16 15 Fig 13 4 2 6 15 1 3 5 16 7 Fig 14
  • 15. 5 4 2 7 15 1 3 6 16 14 Fig 16 4 2 6 15 1 3 5 16 7 14 Fig 15 Deletions can be done with similar rotations
  • 16. Using this you can show that h = O(log N) Rings a bell! Fibonacci numbers FN N S(h) h h is O(log N)