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….!

More Related Content

What's hot

AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
Afaq Mansoor Khan
 
Threaded Binary Tree.pptx
Threaded Binary Tree.pptxThreaded Binary Tree.pptx
Threaded Binary Tree.pptx
pavankumarjakkepalli
 
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
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
Dr. Sindhia Lingaswamy
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
Kamran Zafar
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applicationsJsaddam Hussain
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
sagar yadav
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
Jeanie Arnoco
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
chauhankapil
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
Lemia Algmri
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Abhishek L.R
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
Masud Parvaze
 

What's hot (20)

AVL Tree Data Structure
AVL Tree Data StructureAVL Tree Data Structure
AVL Tree Data Structure
 
Threaded Binary Tree.pptx
Threaded Binary Tree.pptxThreaded Binary Tree.pptx
Threaded Binary Tree.pptx
 
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
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Binary search tree operations
Binary search tree operationsBinary search tree operations
Binary search tree operations
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
b+ tree
b+ treeb+ tree
b+ tree
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 

Similar to AVL Tree in Data Structure

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
 
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
 
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
 

Similar to AVL Tree in Data Structure (11)

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
 
Lecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdfLecture 10 - AVL Trees.pdf
Lecture 10 - AVL Trees.pdf
 
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
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
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
 
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
 
Segment tree
Segment treeSegment tree
Segment tree
 
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
 
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
 
Homework3
Homework3Homework3
Homework3
 
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
 

Recently uploaded

Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 

Recently uploaded (20)

Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 

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 dhanokarvrushali@gmail.com
  • 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