SlideShare a Scribd company logo
Introduction
Insertion
Deletion
Balance Binary Search Tree
Worst case height of binary search tree: N
Insertion, deletion can be O(N) in the worst case
We want a tree with small height
Height of a binary tree with N node is at least Θ(log
N)
Goal: keep the height of a binary search tree O(log N)
Balanced binary search trees
Examples: AVL tree, red-black tree
Balanced Tree?
Suggestion 1: the left and right subtrees of root have the
same height
Suggestion 2: every node must have left and right
subtrees of the same height
Our choice: for each node, the height of the left and
right subtrees can differ at most 1,-1,0.
AVL Tree
An AVL (Adelson-Velskii and Landis 1962) tree is a
binary search tree in which
for every node in the tree, the height of the left and
right subtrees differ by at most 1.
AVL property
violated here
AVL tree
N2 = 2 N3 =4 N4 = N2+N3+1=7
N1 = 1
Height of AVL Tree
Denote Nh the minimum number of nodes in an AVL tree
of height h
N1=1, N2 =2 (base)
Nh= Nh-1 + Nh-2 +1 (recursive relation)
 many operations (i.e. searching) on an AVL tree will
take O(log N) time
Insertion in AVL Tree
Basically follows insertion strategy of binary search
tree
But may cause violation of AVL tree property
Restore the destroyed balance condition if needed
6
7
6 8
Original AVL tree
Insert 6
Property violated
Restore AVL property
Some Observations
After an insertion, only nodes that are on the path from
the insertion point to the root might have their balance
altered
Because only those nodes have their subtrees altered
Rebalance the tree at the deepest such node guarantees
that the entire tree satisfies the AVL property
7
6 8
Rebalance node 7
guarantees the whole tree be AVL
6
Node 5,8,7 might
have balance altered
Different Rebalancing
Rotations
The rebalancing rotations are classified as LL, LR, RR
and RL as illustrated below, based on the position of
the inserted node with reference to α.
LL rotation: Inserted node is in the left subtree of the left
subtree of node α
RR rotation: Inserted node is in the right subtree of the
right subtree of node α
LR rotation: Inserted node is in the right subtree of the
left subtree of node α
RL rotation: Inserted node is in the left subtree of the
right subtree of node α
Insertion Analysis
Insert the new key as a new leaf just as in
ordinary binary search tree: O(logN)
Then trace the path from the new leaf towards
the root, for each node x encountered: O(logN)
Check height difference: O(1)
If satisfies AVL property, proceed to next node: O(1)
If not, perform a rotation: O(1)
The insertion stops when
A single rotation is performed
Or, we’ve checked all nodes in the path
Time complexity for insertion O(logN)
logN
Delete 5, Node 10 is unbalanced Single Rotation
20
10 35
40
15
5 25
18 45
38
30
50
20
15 35
40
18
10 25
45
38
30
50
 Basically follows deletion strategy of binary search tree
 But may cause violation of AVL tree property
 Restore the destroyed balance condition if needed
For deletion, after rotation, we need to continue tracing
upward to see if AVL-tree property is violated at other node.
Different rotations are classified in R0, R1, R-1, L0, L1 And L-1
20
15 35
40
18
10 25
45
38
30
50
20
15
35
40
18
10
25 45
38
30 50
Continue to check parents
Oops!! Node 20 is
unbalanced!!
Single Rotation
Different rotations
• An element can be deleted from AVL tree which
may change the BF of a node such that it results
in unbalanced tree.
• Some rotations will be applied on AVL tree to
balance it.
• R rotation is applied if the deleted node is in the
right subtree of node A (A is the node with
balance factor other than 0, 1 and -1).
• L rotation is applied if the deleted node is in the
left subtree of node A.
Different rotations cont…
• Suppose we have deleted node X from the tree.
• A is the closest ancestor node on the path from X
to the root node, with a balance factor -2 or +2.
• B is the desendent of node A on the opposite
subtree of deleted node i.e. if the deleted node is
on left side the B is the desendent on the right
subtree of A or the root of right subtree of A.
R Rotation
• R Rotation is applied when the deleted node is in the right
subtree of node A.
• There are three different types of rotations based on the
balanced factor of node B.
• R0 Rotation: When the balance Factor of node B is 0.
• Apply LL Rotation on node A.
• R1 Rotation: When the balance Factor of node B is +1.
• Apply LL Rotation on node A.
• R-1 Rotation: When the balance Factor of node B is -1.
• Apply LR Rotation(RR rotation on B and LL rotation on
node A).
L Rotation
• L Rotation is applied when the deleted node is in the
left subtree of node A.
• There are three different types of rotations based on
the balanced factor of node B.
• L0 Rotation: When the balance Factor of node B is 0.
• Apply RR Rotation on node A.
• L-1 Rotation: When the balance Factor of node B is -1.
• Apply RR Rotation on node A.
• L1 Rotation: When the balance Factor of node B is +1.
• Apply RL Rotation(LL rotation on B and RR
rotation on node A).
DS_Mod4_2.pdf

More Related Content

Similar to DS_Mod4_2.pdf

Avl trees
Avl treesAvl trees
Avl trees
Xad Kuain
 
Data structures trees and graphs - AVL tree.pptx
Data structures trees and graphs - AVL  tree.pptxData structures trees and graphs - AVL  tree.pptx
Data structures trees and graphs - AVL tree.pptx
MalligaarjunanN
 
AVL Tree.pptx
AVL Tree.pptxAVL Tree.pptx
AVL Tree.pptx
Trad5
 
Adelson velskii Landis rotations based on
Adelson velskii Landis rotations based onAdelson velskii Landis rotations based on
Adelson velskii Landis rotations based on
banupriyar5
 
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
MuhammadUmerIhtisham
 
CS-102 AVLSv2.pdf
CS-102 AVLSv2.pdfCS-102 AVLSv2.pdf
CS-102 AVLSv2.pdf
ssuser034ce1
 
CS-102 AVLS.pdf
CS-102 AVLS.pdfCS-102 AVLS.pdf
CS-102 AVLS.pdf
ssuser034ce1
 
Avl tree detailed
Avl tree detailedAvl tree detailed
Avl tree detailed
Dr Sandeep Kumar Poonia
 
Avl tree
Avl treeAvl tree
Avl tree
Ajay Singh Rana
 
Study about AVL Tree & Operations
Study about AVL Tree & OperationsStudy about AVL Tree & Operations
Study about AVL Tree & Operations
Editor IJCTER
 
Avl Tree Implementation
Avl Tree ImplementationAvl Tree Implementation
Avl Tree Implementation
Ehsan Elahi
 
TREES.pptx
TREES.pptxTREES.pptx
Avl trees
Avl treesAvl trees
Avl trees
priyapavi96
 
AVL_Trees using DSA concepts and how to do
AVL_Trees using DSA concepts and how to doAVL_Trees using DSA concepts and how to do
AVL_Trees using DSA concepts and how to do
lokaprasaadvs
 
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
Yaksh Jethva
 
Avl tree
Avl treeAvl tree
Avl tree
Van Pham
 
C++ UNIT4.pptx
C++ UNIT4.pptxC++ UNIT4.pptx

Similar to DS_Mod4_2.pdf (20)

Avl trees
Avl treesAvl trees
Avl trees
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Data structures trees and graphs - AVL tree.pptx
Data structures trees and graphs - AVL  tree.pptxData structures trees and graphs - AVL  tree.pptx
Data structures trees and graphs - AVL tree.pptx
 
AVL Tree.pptx
AVL Tree.pptxAVL Tree.pptx
AVL Tree.pptx
 
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
 
Avl tree
Avl treeAvl tree
Avl tree
 
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 tree detailed
Avl tree detailedAvl tree detailed
Avl tree detailed
 
Avl tree
Avl treeAvl tree
Avl tree
 
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
 
Study about AVL Tree & Operations
Study about AVL Tree & OperationsStudy about AVL Tree & Operations
Study about AVL Tree & Operations
 
Avl Tree Implementation
Avl Tree ImplementationAvl Tree Implementation
Avl Tree Implementation
 
TREES.pptx
TREES.pptxTREES.pptx
TREES.pptx
 
Avl trees
Avl treesAvl trees
Avl trees
 
AVL_Trees using DSA concepts and how to do
AVL_Trees using DSA concepts and how to doAVL_Trees using DSA concepts and how to do
AVL_Trees using DSA concepts and how to do
 
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
 
Avl tree
Avl treeAvl tree
Avl tree
 
C++ UNIT4.pptx
C++ UNIT4.pptxC++ UNIT4.pptx
C++ UNIT4.pptx
 

Recently uploaded

space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
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
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
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
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
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
 

Recently uploaded (20)

space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
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
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
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...
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
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
 

DS_Mod4_2.pdf

  • 2. Balance Binary Search Tree Worst case height of binary search tree: N Insertion, deletion can be O(N) in the worst case We want a tree with small height Height of a binary tree with N node is at least Θ(log N) Goal: keep the height of a binary search tree O(log N) Balanced binary search trees Examples: AVL tree, red-black tree
  • 3. Balanced Tree? Suggestion 1: the left and right subtrees of root have the same height Suggestion 2: every node must have left and right subtrees of the same height Our choice: for each node, the height of the left and right subtrees can differ at most 1,-1,0.
  • 4. AVL Tree An AVL (Adelson-Velskii and Landis 1962) tree is a binary search tree in which for every node in the tree, the height of the left and right subtrees differ by at most 1. AVL property violated here AVL tree
  • 5. N2 = 2 N3 =4 N4 = N2+N3+1=7 N1 = 1
  • 6. Height of AVL Tree Denote Nh the minimum number of nodes in an AVL tree of height h N1=1, N2 =2 (base) Nh= Nh-1 + Nh-2 +1 (recursive relation)  many operations (i.e. searching) on an AVL tree will take O(log N) time
  • 7. Insertion in AVL Tree Basically follows insertion strategy of binary search tree But may cause violation of AVL tree property Restore the destroyed balance condition if needed 6 7 6 8 Original AVL tree Insert 6 Property violated Restore AVL property
  • 8. Some Observations After an insertion, only nodes that are on the path from the insertion point to the root might have their balance altered Because only those nodes have their subtrees altered Rebalance the tree at the deepest such node guarantees that the entire tree satisfies the AVL property 7 6 8 Rebalance node 7 guarantees the whole tree be AVL 6 Node 5,8,7 might have balance altered
  • 9. Different Rebalancing Rotations The rebalancing rotations are classified as LL, LR, RR and RL as illustrated below, based on the position of the inserted node with reference to α. LL rotation: Inserted node is in the left subtree of the left subtree of node α RR rotation: Inserted node is in the right subtree of the right subtree of node α LR rotation: Inserted node is in the right subtree of the left subtree of node α RL rotation: Inserted node is in the left subtree of the right subtree of node α
  • 10. Insertion Analysis Insert the new key as a new leaf just as in ordinary binary search tree: O(logN) Then trace the path from the new leaf towards the root, for each node x encountered: O(logN) Check height difference: O(1) If satisfies AVL property, proceed to next node: O(1) If not, perform a rotation: O(1) The insertion stops when A single rotation is performed Or, we’ve checked all nodes in the path Time complexity for insertion O(logN) logN
  • 11. Delete 5, Node 10 is unbalanced Single Rotation 20 10 35 40 15 5 25 18 45 38 30 50 20 15 35 40 18 10 25 45 38 30 50  Basically follows deletion strategy of binary search tree  But may cause violation of AVL tree property  Restore the destroyed balance condition if needed
  • 12. For deletion, after rotation, we need to continue tracing upward to see if AVL-tree property is violated at other node. Different rotations are classified in R0, R1, R-1, L0, L1 And L-1 20 15 35 40 18 10 25 45 38 30 50 20 15 35 40 18 10 25 45 38 30 50 Continue to check parents Oops!! Node 20 is unbalanced!! Single Rotation
  • 13. Different rotations • An element can be deleted from AVL tree which may change the BF of a node such that it results in unbalanced tree. • Some rotations will be applied on AVL tree to balance it. • R rotation is applied if the deleted node is in the right subtree of node A (A is the node with balance factor other than 0, 1 and -1). • L rotation is applied if the deleted node is in the left subtree of node A.
  • 14. Different rotations cont… • Suppose we have deleted node X from the tree. • A is the closest ancestor node on the path from X to the root node, with a balance factor -2 or +2. • B is the desendent of node A on the opposite subtree of deleted node i.e. if the deleted node is on left side the B is the desendent on the right subtree of A or the root of right subtree of A.
  • 15. R Rotation • R Rotation is applied when the deleted node is in the right subtree of node A. • There are three different types of rotations based on the balanced factor of node B. • R0 Rotation: When the balance Factor of node B is 0. • Apply LL Rotation on node A. • R1 Rotation: When the balance Factor of node B is +1. • Apply LL Rotation on node A. • R-1 Rotation: When the balance Factor of node B is -1. • Apply LR Rotation(RR rotation on B and LL rotation on node A).
  • 16. L Rotation • L Rotation is applied when the deleted node is in the left subtree of node A. • There are three different types of rotations based on the balanced factor of node B. • L0 Rotation: When the balance Factor of node B is 0. • Apply RR Rotation on node A. • L-1 Rotation: When the balance Factor of node B is -1. • Apply RR Rotation on node A. • L1 Rotation: When the balance Factor of node B is +1. • Apply RL Rotation(LL rotation on B and RR rotation on node A).