SlideShare a Scribd company logo
1 of 45
PRESENTED BY-
AKASH KUMAR CHAUBEY
CLASS – MCA(1)
SEMESTER : 2
ROLL NO. –MCA/25014/18
AVL TREE
WHAT IS BINARY SEARCHTREE
• Every node contain only two
child.
• Small value at left child node
and large value at right child
nodeas compare to Root node.
• The main advantage of BST is
that it is easy to perform
like inserting,
traversing and
operations
searching,
deleting.
 The disadvantageof skewed binary search tree is that
theworstcase timecomplexityof a search is O(n).
50
40 60
30 45 55 70
Symmetric
40
50
30
20
10
Skewed
 There is a need to maintain the binary search tree to
be of the balanced height, so that it is possible to
obtained for the search option a time complexity of
O(log N) in the worst case.
 One of the most popular balanced tree was introduced
by
A binary tree is said to be an AVL tree if T is
a root of tree and T(L) is its left sub tree
and T(R) is its right sub-tree of tree T and
H(T(L)) and H(T(R)) are the heights of the
left and
right sub-trees of T respectively, and
|H(T(L))
- H(T(R))|<= 1 Then we called T is AVLtree.
Height of left sub-tree minus height of
Right leftsub-tree
[H(T(L)) - H(T(R))]
Note:
 An emptybinary tree isan AVLTree
 Balance Factorshouldbe
-1 0 1
T
T(L) T(R)
T
T(L) T(R)
40
50
30
 If after the insertion of the element the, the
balance factor of any node is affect this
problem is overcome by using rotation.
 Rotation is use to restore the balance of
search tree.
 Toperform the rotation
it is necessary toidentify
a specific node A whose
balance factor (BF) is
neither 0, -1 0r 1 and
which is the nearest
ancestor to the inserted
node on the path from
the inserted node to the
root.
40
50
30
 Single rotation switches the roles of the parent and
child while maintaining the searchorder.
 Werotatea nodeand itschild, child becomes parent
 Parent becomes Right child in LLRotation.
 Parent becomes Left child in RR Rotation.
 Inserted node is in the
left sub-tree of the left
sub-tree of A.
 For LL Rotations identify
A and B, where B is a
Left child of A because
insertion is on leftside.
 Then make A as a child
of B.
40
50
30
40
50
30
50
40
30
Parentbecomes
Rightchild
50
40
30
 Inserted node is in the
right sub-tree of the
Right sub-tree of A.
 For RR Rotations
identify A and B,
where B is a Right
child of A because
insertion is on Right
side.
 Then make A as a child
of B.
60
50
70
60
50
70
70
60
50
Parentbecomes
Left child
50
60
70
 Single rotationdoes not fix the LR rotationand RL
rotation.
 LR and RL rotationsrequireadoublerotation,
involving three node.
 Doublerotation is equivalent toa sequenceof two
single rotation.
 1st rotation on original tree
2nd rotation on the newtree
 Inserted node is inthe
right sub-tree of the left
sub-tree of A.
 For LR Rotations identify A
B and C, where B is a Left
child of A and C is right
child of B because Inserted
node is in the right sub-
tree of the left sub-tree of
A.
 Then make A and B as a
child of C.
40
50
45
40
50
45
50
45
40
 Inserted node is in theleft
sub-tree of the Right sub-
tree of A .
 For RL Rotations identifyA
B and C, where B is aRight
child of A and C is Left
child of B because Inserted
node is in the left sub-tree
of the Right sub-tree of A.
 Then make A and B as a
child of C.
60
50
55
60
50
55
60
55
50
50
60
55
// Left Left Case
if (balance > 1 && key < node->left->key)
return rightRotate(node);
// Right Right Case
if (balance < -1 && key > node->right->key)
return leftRotate(node);
// Left Right Case
if (balance > 1 && key > node->left->key)
{
node->left = leftRotate(node->left);
return rightRotate(node);
}
 // If this node becomes unbalanced, then there are 4 cases





















// Right Left Case
if (balance < -1 && key < node-
>right->key)
{
node->right = rightRotate(node-
>right); return leftRotate(node);
}
5
5
7
5
7
19
5
7
19
19
7
5
19
7
5
19
7
5
12
19
7
5
12
10
19
7
5
12
10
7
5
19
12
10
7
5
19
12
10
7
5
19
12
10
15
7
5
19
12
10
15
12
7 19
155 10
12
7 19
155 10
12
7 19
155 10
18
12
7 19
155 10
18
12
7
5 10
18
15 19
12
7
5 10
18
15 19
12
7
5 10
18
15 19
20
12
7
5 10
18
15 19
20
25
12
7
5 10
18
15 19
20
25
12
7
5 10
18
15 20
19 25
12
7
5 10
18
15 20
19 25
23
12
7
5 10
18
15 20
19 25
23
12
7
5 10
20
18 25
2315 19
www.tutorialspoint.com
www.geeksforgeeks.com
Data Structure by ABDUL BARI
AVL Tree in Data Structure

More Related Content

Similar to AVL Tree in Data Structure

Similar to AVL Tree in Data Structure (14)

Adelson velskii Landis rotations based on
Adelson velskii Landis rotations based onAdelson velskii Landis rotations based on
Adelson velskii Landis rotations based on
 
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
 
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 final
Avl trees finalAvl trees final
Avl trees final
 
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
 
TREES.pptx
TREES.pptxTREES.pptx
TREES.pptx
 
CS-102 AVLSv2.pdf
CS-102 AVLSv2.pdfCS-102 AVLSv2.pdf
CS-102 AVLSv2.pdf
 
CS-102 AVLS.pdf
CS-102 AVLS.pdfCS-102 AVLS.pdf
CS-102 AVLS.pdf
 
Avl trees
Avl treesAvl trees
Avl trees
 
Avl trees 2
Avl trees 2Avl trees 2
Avl trees 2
 
AVL tree PPT.pptx
AVL tree PPT.pptxAVL tree PPT.pptx
AVL tree PPT.pptx
 
AVL Tree.pptx
AVL Tree.pptxAVL Tree.pptx
AVL Tree.pptx
 
Avl excercise
Avl excerciseAvl excercise
Avl excercise
 

More from Meghaj Mallick

PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSMeghaj Mallick
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software TestingMeghaj Mallick
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System ProgrammingMeghaj Mallick
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & MultimediaMeghaj Mallick
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPCMeghaj Mallick
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPTMeghaj Mallick
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringMeghaj Mallick
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningMeghaj Mallick
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmMeghaj Mallick
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development MethodMeghaj Mallick
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodMeghaj Mallick
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in OrganizationMeghaj Mallick
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete MathematicsMeghaj Mallick
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure Meghaj Mallick
 

More from Meghaj Mallick (20)

24 partial-orderings
24 partial-orderings24 partial-orderings
24 partial-orderings
 
PORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSSPORTFOLIO BY USING HTML & CSS
PORTFOLIO BY USING HTML & CSS
 
Introduction to Software Testing
Introduction to Software TestingIntroduction to Software Testing
Introduction to Software Testing
 
Introduction to System Programming
Introduction to System ProgrammingIntroduction to System Programming
Introduction to System Programming
 
MACRO ASSEBLER
MACRO ASSEBLERMACRO ASSEBLER
MACRO ASSEBLER
 
Icons, Image & Multimedia
Icons, Image & MultimediaIcons, Image & Multimedia
Icons, Image & Multimedia
 
Project Tracking & SPC
Project Tracking & SPCProject Tracking & SPC
Project Tracking & SPC
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Routing in MANET
Routing in MANETRouting in MANET
Routing in MANET
 
Macro assembler
 Macro assembler Macro assembler
Macro assembler
 
Architecture and security in Vanet PPT
Architecture and security in Vanet PPTArchitecture and security in Vanet PPT
Architecture and security in Vanet PPT
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
 
Text Mining of Twitter in Data Mining
Text Mining of Twitter in Data MiningText Mining of Twitter in Data Mining
Text Mining of Twitter in Data Mining
 
DFS & BFS in Computer Algorithm
DFS & BFS in Computer AlgorithmDFS & BFS in Computer Algorithm
DFS & BFS in Computer Algorithm
 
Software Development Method
Software Development MethodSoftware Development Method
Software Development Method
 
Secant method in Numerical & Statistical Method
Secant method in Numerical & Statistical MethodSecant method in Numerical & Statistical Method
Secant method in Numerical & Statistical Method
 
Motivation in Organization
Motivation in OrganizationMotivation in Organization
Motivation in Organization
 
Communication Skill
Communication SkillCommunication Skill
Communication Skill
 
Partial-Orderings in Discrete Mathematics
 Partial-Orderings in Discrete Mathematics Partial-Orderings in Discrete Mathematics
Partial-Orderings in Discrete Mathematics
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 

Recently uploaded

My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Baileyhlharris
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lodhisaajjda
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoKayode Fayemi
 
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINES
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINESBIG DEVELOPMENTS IN LESOTHO(DAMS & MINES
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINESfuthumetsaneliswa
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatmentnswingard
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityHung Le
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...ZurliaSoop
 
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptx
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptxBEAUTIFUL PLACES TO VISIT IN LESOTHO.pptx
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptxthusosetemere
 
Lions New Portal from Narsimha Raju Dichpally 320D.pptx
Lions New Portal from Narsimha Raju Dichpally 320D.pptxLions New Portal from Narsimha Raju Dichpally 320D.pptx
Lions New Portal from Narsimha Raju Dichpally 320D.pptxlionnarsimharajumjf
 
History of Morena Moshoeshoe birth death
History of Morena Moshoeshoe birth deathHistory of Morena Moshoeshoe birth death
History of Morena Moshoeshoe birth deathphntsoaki
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.thamaeteboho94
 
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORN
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORNLITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORN
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORNtntlai16
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfMahamudul Hasan
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...David Celestin
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIINhPhngng3
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfSkillCertProExams
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalFabian de Rijk
 
Ready Set Go Children Sermon about Mark 16:15-20
Ready Set Go Children Sermon about Mark 16:15-20Ready Set Go Children Sermon about Mark 16:15-20
Ready Set Go Children Sermon about Mark 16:15-20rejz122017
 

Recently uploaded (20)

in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait Cityin kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINES
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINESBIG DEVELOPMENTS IN LESOTHO(DAMS & MINES
BIG DEVELOPMENTS IN LESOTHO(DAMS & MINES
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
 
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptx
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptxBEAUTIFUL PLACES TO VISIT IN LESOTHO.pptx
BEAUTIFUL PLACES TO VISIT IN LESOTHO.pptx
 
Lions New Portal from Narsimha Raju Dichpally 320D.pptx
Lions New Portal from Narsimha Raju Dichpally 320D.pptxLions New Portal from Narsimha Raju Dichpally 320D.pptx
Lions New Portal from Narsimha Raju Dichpally 320D.pptx
 
History of Morena Moshoeshoe birth death
History of Morena Moshoeshoe birth deathHistory of Morena Moshoeshoe birth death
History of Morena Moshoeshoe birth death
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.
 
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORN
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORNLITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORN
LITTLE ABOUT LESOTHO FROM THE TIME MOSHOESHOE THE FIRST WAS BORN
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
Ready Set Go Children Sermon about Mark 16:15-20
Ready Set Go Children Sermon about Mark 16:15-20Ready Set Go Children Sermon about Mark 16:15-20
Ready Set Go Children Sermon about Mark 16:15-20
 

AVL Tree in Data Structure

  • 1. PRESENTED BY- AKASH KUMAR CHAUBEY CLASS – MCA(1) SEMESTER : 2 ROLL NO. –MCA/25014/18 AVL TREE
  • 2. WHAT IS BINARY SEARCHTREE • Every node contain only two child. • Small value at left child node and large value at right child nodeas compare to Root node. • The main advantage of BST is that it is easy to perform like inserting, traversing and operations searching, deleting.
  • 3.  The disadvantageof skewed binary search tree is that theworstcase timecomplexityof a search is O(n). 50 40 60 30 45 55 70 Symmetric 40 50 30 20 10 Skewed
  • 4.  There is a need to maintain the binary search tree to be of the balanced height, so that it is possible to obtained for the search option a time complexity of O(log N) in the worst case.  One of the most popular balanced tree was introduced by
  • 5. A binary tree is said to be an AVL tree if T is a root of tree and T(L) is its left sub tree and T(R) is its right sub-tree of tree T and H(T(L)) and H(T(R)) are the heights of the left and right sub-trees of T respectively, and |H(T(L)) - H(T(R))|<= 1 Then we called T is AVLtree. Height of left sub-tree minus height of Right leftsub-tree [H(T(L)) - H(T(R))] Note:  An emptybinary tree isan AVLTree  Balance Factorshouldbe -1 0 1 T T(L) T(R)
  • 8.  If after the insertion of the element the, the balance factor of any node is affect this problem is overcome by using rotation.  Rotation is use to restore the balance of search tree.
  • 9.  Toperform the rotation it is necessary toidentify a specific node A whose balance factor (BF) is neither 0, -1 0r 1 and which is the nearest ancestor to the inserted node on the path from the inserted node to the root. 40 50 30
  • 10.  Single rotation switches the roles of the parent and child while maintaining the searchorder.  Werotatea nodeand itschild, child becomes parent  Parent becomes Right child in LLRotation.  Parent becomes Left child in RR Rotation.
  • 11.  Inserted node is in the left sub-tree of the left sub-tree of A.  For LL Rotations identify A and B, where B is a Left child of A because insertion is on leftside.  Then make A as a child of B. 40 50 30
  • 13.  Inserted node is in the right sub-tree of the Right sub-tree of A.  For RR Rotations identify A and B, where B is a Right child of A because insertion is on Right side.  Then make A as a child of B. 60 50 70
  • 15.  Single rotationdoes not fix the LR rotationand RL rotation.  LR and RL rotationsrequireadoublerotation, involving three node.  Doublerotation is equivalent toa sequenceof two single rotation.  1st rotation on original tree 2nd rotation on the newtree
  • 16.  Inserted node is inthe right sub-tree of the left sub-tree of A.  For LR Rotations identify A B and C, where B is a Left child of A and C is right child of B because Inserted node is in the right sub- tree of the left sub-tree of A.  Then make A and B as a child of C. 40 50 45
  • 18.  Inserted node is in theleft sub-tree of the Right sub- tree of A .  For RL Rotations identifyA B and C, where B is aRight child of A and C is Left child of B because Inserted node is in the left sub-tree of the Right sub-tree of A.  Then make A and B as a child of C. 60 50 55
  • 20. // Left Left Case if (balance > 1 && key < node->left->key) return rightRotate(node); // Right Right Case if (balance < -1 && key > node->right->key) return leftRotate(node); // Left Right Case if (balance > 1 && key > node->left->key) { node->left = leftRotate(node->left); return rightRotate(node); }  // If this node becomes unbalanced, then there are 4 cases                      // Right Left Case if (balance < -1 && key < node- >right->key) { node->right = rightRotate(node- >right); return leftRotate(node); }
  • 21.
  • 22. 5
  • 23. 5 7