SlideShare a Scribd company logo
Data Structure & Files
Unit 5: Advance Tree
AVL Tree
Ms. Vrushali Dhanokar (M.Tech CSE)
Assistant Professor
IT Department
dhanokarvrushali@gmail.com
Why AVL Tree?
Example: Keys are: 1, 2, 3, 4, 5, 6, 7. Generate Binary Tree.
• Fig 1: AVL Tree
• Fig 2. Binary Tree
• Insert 8 in BT: 7 comparisons.
• Insert 8 in AVL: 3 comparisons.
So, AVL Tree:
• Height balance trees.
• Insertion and deletion have low
time complexity.
What is AVL Tree?
• AVL invented by G.M. Adelson-Velsky and E.M. Landis. So, name is AVL.
• AVL tree is a height-balanced binary search tree.
• AVL tree, balance factor of every node is either -1, 0 or +1.
• Every node maintains an extra information known as balance factor.
• Balance factor = heightOfLeftSubtree – heightOfRightSubtree.
• Every AVL Tree is a binary search tree but every Binary Search Tree need not be AVL tree.
• Operation perform Search, Insertion, Deletion with O(log n) time complexity.
AVL Tree Rotations:
Type 1: RR Relationship (Left Rotation):
Type 2: LL Relationship (Right Rotation)
AVL Tree Rotations:
Type 3: LR Relationship (First Left Rotation then Right Rotation)
Type 4: RL Relationship (First Right Rotation then Left Rotation)
Insertion Operations In AVL Tree
In AVL Tree, a new node is always inserted as a leaf node.
Step 1 - Insert the new element into the tree using Binary Search Tree insertion logic.
Step 2 - After insertion, check the Balance Factor of every node.
Step 3 - If the Balance Factor of every node is 0 or 1 or -1 then go for next operation.
Step 4 - If the Balance Factor of any node is other than 0 or 1 or -1 then that tree is said to
be imbalanced. In this case, perform suitable Rotation to make it balanced and go for
next operation.
Example of Insertion Operation in AVL Tree
Que. Construct AVL Tree by inserting number from 1 to 8.
Continue..
Continue..
Difference Between Red Black Tree & AVL Tree
Important Questions
By SPPU Exam Pattern
1. Define Balance Factor of a node in a Binary Tree. 2M
2. What are the benefits of AVL Tree over BST? 4M
3. Explain Insertion operation in AVL tree with suitable example. 5M
4. Obtain AVL tree of following data element
50,55,60,15,10,40,20,45,30,70,80. 8M
5. Build AVL Tree of Sun, Fri, Mon, Wed, Tue, Thurs, Sat. 8M
6. Build AVL Tree of A,Z,B,Y,C,X,D,U. 8M
7. Build AVL Tree of MAR,MAY,NOV,AUG,APR,JAN,DEC,JUL. 8M
(Use lexicographic order i.e April ……. Sept)
8. Difference Between Red Black Tree & AVL Tree. 6M
Thank You….!
Ad

More Related Content

What's hot (20)

Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
Md. Israil Fakir
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
sagar yadav
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
shameen khan
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Binary tree
Binary treeBinary tree
Binary tree
Rajendran
 
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
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations
varagilavanya
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
RacksaviR
 
B+ Tree
B+ TreeB+ Tree
B+ Tree
Mujahid Hussain Jalbani
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
Anuj Modi
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
Afaq Mansoor Khan
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Binary tree
Binary  treeBinary  tree
Binary tree
Vanitha Chandru
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 

Similar to AVL Tree in Data Structure (16)

Introduction to AVL Tree, Different kinds of rotations and insertion, deletion
Introduction to AVL Tree, Different kinds of rotations and insertion, deletionIntroduction to AVL Tree, Different kinds of rotations and insertion, deletion
Introduction to AVL Tree, Different kinds of rotations and insertion, deletion
proshantasarkar3
 
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
AnyaForger34
 
Lecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdfLecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdf
SanghdipUdrake
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docx
mary772
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
VijayaLakshmi506
 
Presentation_30219_Content_Document_20250107125144AM.pptx
Presentation_30219_Content_Document_20250107125144AM.pptxPresentation_30219_Content_Document_20250107125144AM.pptx
Presentation_30219_Content_Document_20250107125144AM.pptx
chiraglab007
 
ADSPPT.pptx advanced data structures presentation
ADSPPT.pptx advanced data structures presentationADSPPT.pptx advanced data structures presentation
ADSPPT.pptx advanced data structures presentation
YashDubal5
 
Unit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdfUnit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdf
KanchanPatil34
 
Unit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdfUnit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdf
KanchanPatil34
 
Trees second part in data structures with examples
Trees second part in data structures with examplesTrees second part in data structures with examples
Trees second part in data structures with examples
rupanaveen24
 
Segment tree
Segment treeSegment tree
Segment tree
Sindhuja Kumar
 
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
sumitbardhan
 
Linked List vs. AVL Tree in Modulo Ten Search
Linked List vs. AVL Tree in Modulo Ten SearchLinked List vs. AVL Tree in Modulo Ten Search
Linked List vs. AVL Tree in Modulo Ten Search
IJCSIS Research Publications
 
Homework3
Homework3Homework3
Homework3
Steve Merritt
 
Unit-3.pptUnit-3.pptUnit-3.pptUnit-3.ppt
Unit-3.pptUnit-3.pptUnit-3.pptUnit-3.pptUnit-3.pptUnit-3.pptUnit-3.pptUnit-3.ppt
Unit-3.pptUnit-3.pptUnit-3.pptUnit-3.ppt
DiveshDutt3
 
Assignment Two Objectives • Understand how the.docx
Assignment Two   Objectives • Understand how the.docxAssignment Two   Objectives • Understand how the.docx
Assignment Two Objectives • Understand how the.docx
lynettearnold46882
 
Introduction to AVL Tree, Different kinds of rotations and insertion, deletion
Introduction to AVL Tree, Different kinds of rotations and insertion, deletionIntroduction to AVL Tree, Different kinds of rotations and insertion, deletion
Introduction to AVL Tree, Different kinds of rotations and insertion, deletion
proshantasarkar3
 
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
AnyaForger34
 
Lecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdfLecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdf
SanghdipUdrake
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docx
mary772
 
Presentation_30219_Content_Document_20250107125144AM.pptx
Presentation_30219_Content_Document_20250107125144AM.pptxPresentation_30219_Content_Document_20250107125144AM.pptx
Presentation_30219_Content_Document_20250107125144AM.pptx
chiraglab007
 
ADSPPT.pptx advanced data structures presentation
ADSPPT.pptx advanced data structures presentationADSPPT.pptx advanced data structures presentation
ADSPPT.pptx advanced data structures presentation
YashDubal5
 
Unit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdfUnit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdf
KanchanPatil34
 
Unit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdfUnit 1_Stack and Queue using Linked Organization.pdf
Unit 1_Stack and Queue using Linked Organization.pdf
KanchanPatil34
 
Trees second part in data structures with examples
Trees second part in data structures with examplesTrees second part in data structures with examples
Trees second part in data structures with examples
rupanaveen24
 
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
sumitbardhan
 
Unit-3.pptUnit-3.pptUnit-3.pptUnit-3.ppt
Unit-3.pptUnit-3.pptUnit-3.pptUnit-3.pptUnit-3.pptUnit-3.pptUnit-3.pptUnit-3.ppt
Unit-3.pptUnit-3.pptUnit-3.pptUnit-3.ppt
DiveshDutt3
 
Assignment Two Objectives • Understand how the.docx
Assignment Two   Objectives • Understand how the.docxAssignment Two   Objectives • Understand how the.docx
Assignment Two Objectives • Understand how the.docx
lynettearnold46882
 
Ad

Recently uploaded (20)

Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.Fort night presentation new0903 pdf.pdf.
Fort night presentation new0903 pdf.pdf.
anuragmk56
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Ad

AVL Tree in Data Structure

  • 1. Data Structure & Files Unit 5: Advance Tree AVL Tree Ms. Vrushali Dhanokar (M.Tech CSE) Assistant Professor IT Department [email protected]
  • 2. Why AVL Tree? Example: Keys are: 1, 2, 3, 4, 5, 6, 7. Generate Binary Tree. • Fig 1: AVL Tree • Fig 2. Binary Tree • Insert 8 in BT: 7 comparisons. • Insert 8 in AVL: 3 comparisons. So, AVL Tree: • Height balance trees. • Insertion and deletion have low time complexity.
  • 3. What is AVL Tree? • AVL invented by G.M. Adelson-Velsky and E.M. Landis. So, name is AVL. • AVL tree is a height-balanced binary search tree. • AVL tree, balance factor of every node is either -1, 0 or +1. • Every node maintains an extra information known as balance factor. • Balance factor = heightOfLeftSubtree – heightOfRightSubtree. • Every AVL Tree is a binary search tree but every Binary Search Tree need not be AVL tree. • Operation perform Search, Insertion, Deletion with O(log n) time complexity.
  • 4. AVL Tree Rotations: Type 1: RR Relationship (Left Rotation): Type 2: LL Relationship (Right Rotation)
  • 5. AVL Tree Rotations: Type 3: LR Relationship (First Left Rotation then Right Rotation) Type 4: RL Relationship (First Right Rotation then Left Rotation)
  • 6. Insertion Operations In AVL Tree In AVL Tree, a new node is always inserted as a leaf node. Step 1 - Insert the new element into the tree using Binary Search Tree insertion logic. Step 2 - After insertion, check the Balance Factor of every node. Step 3 - If the Balance Factor of every node is 0 or 1 or -1 then go for next operation. Step 4 - If the Balance Factor of any node is other than 0 or 1 or -1 then that tree is said to be imbalanced. In this case, perform suitable Rotation to make it balanced and go for next operation.
  • 7. Example of Insertion Operation in AVL Tree Que. Construct AVL Tree by inserting number from 1 to 8.
  • 10. Difference Between Red Black Tree & AVL Tree
  • 11. Important Questions By SPPU Exam Pattern 1. Define Balance Factor of a node in a Binary Tree. 2M 2. What are the benefits of AVL Tree over BST? 4M 3. Explain Insertion operation in AVL tree with suitable example. 5M 4. Obtain AVL tree of following data element 50,55,60,15,10,40,20,45,30,70,80. 8M 5. Build AVL Tree of Sun, Fri, Mon, Wed, Tue, Thurs, Sat. 8M 6. Build AVL Tree of A,Z,B,Y,C,X,D,U. 8M 7. Build AVL Tree of MAR,MAY,NOV,AUG,APR,JAN,DEC,JUL. 8M (Use lexicographic order i.e April ……. Sept) 8. Difference Between Red Black Tree & AVL Tree. 6M