SlideShare une entreprise Scribd logo
1  sur  17
AVL Trees

1
Presentation
Data Structure & Algorithms
Presented By: Group 11
By
Komal 6622
Tayyaba 6648
Maryam 6626
Kanwal 6619
Mahnoor 6623
AVL Trees

2
AVL Trees

6

v
8

3

z
4

AVL Trees

3
Contents
1) Defination
2) Why we need?
3) Difference beteen AVL and Non AVL
by example
4) Techniques with examples
5) Advantage and Disadvantage
6) Time complexity
AVL Trees

4
 

AVL Trees:
AVL trees were invented in 1962 by two Russian
scientist G.M Adelson Velsky & E.M Landis.

Definition:
An AVL tree is a binary search tree in
which the balance factor of every node is
either 0 or +1 or -1 .
Height Of A Tree:
The height of a binary tree is the
maximum path length from root to the leaf
Level 0
Level 1
Level 2
Level 3
The height of this tree is= 3

AVL Trees

6
Balance Factor:
 It is defined as the difference b/w the
heights of the node’s left & right sub trees

 Balance factor=ht of left sub tree – ht of
right sub tree.

 ht=height
AVL Trees

7
Why we need AVL Tree?
o To keep binary search tree perfectly
balanced we need AVL Tree with
O(log N) complexity…

AVL Trees

8
Example :

AVL tree

BST ( not AVL tree )

1

2

0
0

0
-1

0

0

0
0

0

0
-1

0

0
Techniques
to make AVL Tree:
If an insertion of a new node makes an AVL tree
unbalanced , we transform the tree by a rotation
there are four types of rotation we have:

1.
2.
3.
4.

Single right rotation or R-rotation
Single left rotation or L-rotation
Double right-left rotation or RL-rotation
Double left-right rotation or LR-rotation
AVL Trees

10
 

1.Straight line with positive unbalanced.
apply Right rotation for unbalanced node.
+2

+1
0

2

4

5

0 4
0 2

0

5
 

2.Straight line with negative unbalanced.
apply left rotation for unbalanced node.
5

-2
0
6 -1
7

0 5
0

6
0 7
 

3.Curved line with positive unbalanced.
apply left-right rotation.

Right rotation for unbalanced node and left
rotation for the nearest node.
For example: C,A,B
+2
C

C

0 B

B

A -1
B

0

A

0

A

C

0
 

4.Curved line with negative unbalanced.
apply right-left rotation.

Left rotation for unbalanced node and right
rotation for the nearest node.
For example: A,C,B
A -2
C
B

0

A

0 B

B
+1

C

0

A

C

0
Advantages &Disadvantages
 The advantage of an AVL tree is that it
is always balanced, guaranteeing the
O(logn) speed of the Binary Search
algorithm.
 The disadvantages the complex
rotations used by the insertion and
removal
AVL Trees

15
Running Times for AVL
Trees
find is O(log n)
 height of tree is O(log n)
insert is O(log n)
 initial find is O(log n)
remove is O(log n)
 initial remove is O(log n)
AVL Trees

16
Thank You

AVL Trees

17

Contenu connexe

Tendances

Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data miningKamal Acharya
 
Activation function
Activation functionActivation function
Activation functionAstha Jain
 
GRAPH COLORING AND ITS APPLICATIONS
GRAPH COLORING AND ITS APPLICATIONSGRAPH COLORING AND ITS APPLICATIONS
GRAPH COLORING AND ITS APPLICATIONSManojit Chakraborty
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languagesparmeet834
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
Batch normalization presentation
Batch normalization presentationBatch normalization presentation
Batch normalization presentationOwin Will
 
Overfitting & Underfitting
Overfitting & UnderfittingOverfitting & Underfitting
Overfitting & UnderfittingSOUMIT KAR
 
Parallel Algorithm Models
Parallel Algorithm ModelsParallel Algorithm Models
Parallel Algorithm ModelsMartin Coronel
 
An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms Hakky St
 
Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)Falak Chaudry
 

Tendances (20)

Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Activation function
Activation functionActivation function
Activation function
 
Graph colouring
Graph colouringGraph colouring
Graph colouring
 
Planar graph
Planar graphPlanar graph
Planar graph
 
GRAPH COLORING AND ITS APPLICATIONS
GRAPH COLORING AND ITS APPLICATIONSGRAPH COLORING AND ITS APPLICATIONS
GRAPH COLORING AND ITS APPLICATIONS
 
Regular Languages
Regular LanguagesRegular Languages
Regular Languages
 
Graph representation
Graph representationGraph representation
Graph representation
 
Batch normalization presentation
Batch normalization presentationBatch normalization presentation
Batch normalization presentation
 
Graph coloring
Graph coloringGraph coloring
Graph coloring
 
Np complete
Np completeNp complete
Np complete
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
 
Overfitting & Underfitting
Overfitting & UnderfittingOverfitting & Underfitting
Overfitting & Underfitting
 
b+ tree
b+ treeb+ tree
b+ tree
 
Parallel Algorithm Models
Parallel Algorithm ModelsParallel Algorithm Models
Parallel Algorithm Models
 
An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms
 
Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)Alpha-beta pruning (Artificial Intelligence)
Alpha-beta pruning (Artificial Intelligence)
 
5 csp
5 csp5 csp
5 csp
 

En vedette

Discrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIDiscrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIWongyos Keardsri
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Treecinterviews
 
Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Fahrul Usman
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphsmaznabili
 
Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics TreeMasud Parvaze
 
Relations digraphs
Relations  digraphsRelations  digraphs
Relations digraphsIIUM
 
Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 

En vedette (10)

Discrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIDiscrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part II
 
Trees
Trees Trees
Trees
 
Trees
TreesTrees
Trees
 
Cinterviews Binarysearch Tree
Cinterviews Binarysearch TreeCinterviews Binarysearch Tree
Cinterviews Binarysearch Tree
 
Discrete-Chapter 10 Trees
Discrete-Chapter 10 TreesDiscrete-Chapter 10 Trees
Discrete-Chapter 10 Trees
 
Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)Discrete Mathematics & Its Applications (Graphs)
Discrete Mathematics & Its Applications (Graphs)
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphs
 
Discrete Mathematics Tree
Discrete Mathematics  TreeDiscrete Mathematics  Tree
Discrete Mathematics Tree
 
Relations digraphs
Relations  digraphsRelations  digraphs
Relations digraphs
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 

Similaire à Avltrees

Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesManishPrajapati78
 
AVL Tree.pptx
AVL Tree.pptxAVL Tree.pptx
AVL Tree.pptxTrad5
 
Lecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdfLecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdfSanghdipUdrake
 
Study about AVL Tree & Operations
Study about AVL Tree & OperationsStudy about AVL Tree & Operations
Study about AVL Tree & OperationsEditor IJCTER
 
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
 
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
 
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.pdfMuhammadUmerIhtisham
 
Avltrees 121106175039-phpapp01
Avltrees 121106175039-phpapp01Avltrees 121106175039-phpapp01
Avltrees 121106175039-phpapp01queenmarry
 
Avl trees
Avl treesAvl trees
Avl treesppreeta
 

Similaire à Avltrees (20)

DS_Mod4_2.pdf
DS_Mod4_2.pdfDS_Mod4_2.pdf
DS_Mod4_2.pdf
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
 
AVL tree PPT.pptx
AVL tree PPT.pptxAVL tree PPT.pptx
AVL tree PPT.pptx
 
4. avl
4. avl4. avl
4. avl
 
3-avl-tree.ppt
3-avl-tree.ppt3-avl-tree.ppt
3-avl-tree.ppt
 
Avl tree ppt
Avl tree pptAvl tree ppt
Avl tree ppt
 
AVL Tree.pptx
AVL Tree.pptxAVL Tree.pptx
AVL Tree.pptx
 
Avl tree
Avl treeAvl tree
Avl tree
 
Lecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdfLecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdf
 
Study about AVL Tree & Operations
Study about AVL Tree & OperationsStudy about AVL Tree & Operations
Study about AVL Tree & Operations
 
Avl tree
Avl treeAvl tree
Avl tree
 
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
 
Tree
TreeTree
Tree
 
Avl tree algorithm
Avl tree algorithmAvl tree algorithm
Avl tree algorithm
 
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
 
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
 
AVL_Trees.ppt
AVL_Trees.pptAVL_Trees.ppt
AVL_Trees.ppt
 
Avltrees 121106175039-phpapp01
Avltrees 121106175039-phpapp01Avltrees 121106175039-phpapp01
Avltrees 121106175039-phpapp01
 
Avl trees
Avl treesAvl trees
Avl trees
 
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
 

Dernier

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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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
 
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
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Dernier (20)

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
 
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"
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
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...
 
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
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).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 ...
 
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
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Avltrees

  • 2. Presentation Data Structure & Algorithms Presented By: Group 11 By Komal 6622 Tayyaba 6648 Maryam 6626 Kanwal 6619 Mahnoor 6623 AVL Trees 2
  • 4. Contents 1) Defination 2) Why we need? 3) Difference beteen AVL and Non AVL by example 4) Techniques with examples 5) Advantage and Disadvantage 6) Time complexity AVL Trees 4
  • 5.   AVL Trees: AVL trees were invented in 1962 by two Russian scientist G.M Adelson Velsky & E.M Landis. Definition: An AVL tree is a binary search tree in which the balance factor of every node is either 0 or +1 or -1 .
  • 6. Height Of A Tree: The height of a binary tree is the maximum path length from root to the leaf Level 0 Level 1 Level 2 Level 3 The height of this tree is= 3 AVL Trees 6
  • 7. Balance Factor:  It is defined as the difference b/w the heights of the node’s left & right sub trees  Balance factor=ht of left sub tree – ht of right sub tree.  ht=height AVL Trees 7
  • 8. Why we need AVL Tree? o To keep binary search tree perfectly balanced we need AVL Tree with O(log N) complexity… AVL Trees 8
  • 9. Example : AVL tree BST ( not AVL tree ) 1 2 0 0 0 -1 0 0 0 0 0 0 -1 0 0
  • 10. Techniques to make AVL Tree: If an insertion of a new node makes an AVL tree unbalanced , we transform the tree by a rotation there are four types of rotation we have: 1. 2. 3. 4. Single right rotation or R-rotation Single left rotation or L-rotation Double right-left rotation or RL-rotation Double left-right rotation or LR-rotation AVL Trees 10
  • 11.   1.Straight line with positive unbalanced. apply Right rotation for unbalanced node. +2 +1 0 2 4 5 0 4 0 2 0 5
  • 12.   2.Straight line with negative unbalanced. apply left rotation for unbalanced node. 5 -2 0 6 -1 7 0 5 0 6 0 7
  • 13.   3.Curved line with positive unbalanced. apply left-right rotation. Right rotation for unbalanced node and left rotation for the nearest node. For example: C,A,B +2 C C 0 B B A -1 B 0 A 0 A C 0
  • 14.   4.Curved line with negative unbalanced. apply right-left rotation. Left rotation for unbalanced node and right rotation for the nearest node. For example: A,C,B A -2 C B 0 A 0 B B +1 C 0 A C 0
  • 15. Advantages &Disadvantages  The advantage of an AVL tree is that it is always balanced, guaranteeing the O(logn) speed of the Binary Search algorithm.  The disadvantages the complex rotations used by the insertion and removal AVL Trees 15
  • 16. Running Times for AVL Trees find is O(log n)  height of tree is O(log n) insert is O(log n)  initial find is O(log n) remove is O(log n)  initial remove is O(log n) AVL Trees 16