SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Himanshu Choudhary
 
ECG In Ischemic Heart Disease - Dr Vivek Baliga Review
ECG In Ischemic Heart Disease - Dr Vivek Baliga ReviewECG In Ischemic Heart Disease - Dr Vivek Baliga Review
ECG In Ischemic Heart Disease - Dr Vivek Baliga ReviewDr Vivek Baliga
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesManishPrajapati78
 
Dc circuits
Dc circuitsDc circuits
Dc circuitsEkeeda
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search treeKrish_ver2
 
Wide QRS Complex Tachycardia (VT vs SVT)
Wide QRS Complex Tachycardia (VT vs SVT)Wide QRS Complex Tachycardia (VT vs SVT)
Wide QRS Complex Tachycardia (VT vs SVT)Mohit Goyal
 

What's hot (14)

Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++
 
Involutes
InvolutesInvolutes
Involutes
 
ECG In Ischemic Heart Disease - Dr Vivek Baliga Review
ECG In Ischemic Heart Disease - Dr Vivek Baliga ReviewECG In Ischemic Heart Disease - Dr Vivek Baliga Review
ECG In Ischemic Heart Disease - Dr Vivek Baliga Review
 
Data Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL TreesData Structure and Algorithms AVL Trees
Data Structure and Algorithms AVL Trees
 
Dc circuits
Dc circuitsDc circuits
Dc circuits
 
Ecg case
Ecg caseEcg case
Ecg case
 
Basic ecg
Basic ecgBasic ecg
Basic ecg
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Avl trees
Avl treesAvl trees
Avl trees
 
b+ tree
b+ treeb+ tree
b+ tree
 
Defibrillators - Medical Equipment
Defibrillators - Medical EquipmentDefibrillators - Medical Equipment
Defibrillators - Medical Equipment
 
Axis
AxisAxis
Axis
 
Wide QRS Complex Tachycardia (VT vs SVT)
Wide QRS Complex Tachycardia (VT vs SVT)Wide QRS Complex Tachycardia (VT vs SVT)
Wide QRS Complex Tachycardia (VT vs SVT)
 
Segment tree
Segment treeSegment tree
Segment tree
 

Viewers also liked

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
 

Viewers also liked (11)

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 and graphs
Trees and graphsTrees and graphs
Trees and graphs
 
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
 

Similar to Avltrees

Similar to Avltrees (20)

DS_Mod4_2.pdf
DS_Mod4_2.pdfDS_Mod4_2.pdf
DS_Mod4_2.pdf
 
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
 
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
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuuavltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
avltreesUNIT4.ppt ggggggggggggggguuuuuuuuu
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu 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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
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"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
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...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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