SlideShare a Scribd company logo
WHAT IS BINARY SEARCH TREE
• Every node contain only two
child.
• Small value at left child node
and large value at right child
node as compare to Root node.
• The main advantage of BST is
that it is easy to perform
operations like inserting,
searching, traversing and
deleting.
Prepared By: Awais Ahmad
 The disadvantage of skewed binary search tree is that
the worst case time complexity of a search is O(n).
50
40 60
30 45 55 70
40
50
30
20
10
Symmetric Skewed
Prepared By: Awais Ahmad
 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
Prepared By: Awais Ahmad
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 AVL tree.
Height of left sub-tree minus height of Right
left sub-tree
[H(T(L)) - H(T(R))]
Note:
 An empty binary tree is an AVL Tree
 Balance Factor should be
-1 0 1
T
T(L) T(R)
Prepared By: Awais Ahmad
T
T(L) T(R)
Prepared By: Awais Ahmad
40
50
30
Prepared By: Awais Ahmad
 If after the insertion of the element the, the
balance factor of any node is affect this
problem is over come by using rotation.
 Rotation is use to restore the balance of
search tree.
Prepared By: Awais Ahmad
 To perform the rotation
it is necessary to identify
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
Prepared By: Awais Ahmad
LL(Left Left) rotation.
RR(Right Right) rotation.
RL(Right Left) rotation.
LR( Left Right) rotation
Prepared By: Awais Ahmad
 Single rotation switches the roles of the parent and
child while maintaining the search order.
 We rotate a node and its child, child becomes parent
 Parent becomes Right child in LL Rotation.
 Parent becomes Left child in RR Rotation.
Prepared By: Awais Ahmad
 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 left side.
 Then make A as a child
of B.
40
50
30
Prepared By: Awais Ahmad
40
50
30
50
40
30
Parent becomes
Right child
Prepared By: Awais Ahmad
 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
Prepared By: Awais Ahmad
60
50
70
70
60
50
Parent becomes
Left child
Prepared By: Awais Ahmad
 Single rotation does not fix the LR rotation and RL
rotation.
 LR and RL rotations require a double rotation,
involving three node.
 Double rotation is equivalent to a sequence of two
single rotation.
 1st rotation on original tree
 2nd rotation on the new tree
Prepared By: Awais Ahmad
 Inserted node is in the
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
Prepared By: Awais Ahmad
40
50
45
50
45
40
Prepared By: Awais Ahmad
 Inserted node is in the left
sub-tree of the Right sub-
tree of A .
 For RL Rotations identify A
B and C, where B is a Right
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
Prepared By: Awais Ahmad
60
50
55
60
55
50
Prepared By: Awais Ahmad
 // If this node becomes unbalanced, then there are 4 cases

 // 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);
 }

 // Right Left Case
 if (balance < -1 && key < node->right->key)
 {
 node->right = rightRotate(node->right);
 return leftRotate(node);
 }
Prepared By: Awais Ahmad
Prepared By: Awais Ahmad
5
Prepared By: Awais Ahmad
5
7
Prepared By: Awais Ahmad
5
7
19
Prepared By: Awais Ahmad
5
7
19
19
7
5
Prepared By: Awais Ahmad
19
7
5
Prepared By: Awais Ahmad
19
7
5
12
Prepared By: Awais Ahmad
19
7
5
12
10
Prepared By: Awais Ahmad
19
7
5
12
10
7
5
19
12
10
Prepared By: Awais Ahmad
7
5
19
12
10
Prepared By: Awais Ahmad
7
5
19
12
10
15
Prepared By: Awais Ahmad
7
5
19
12
10
15
12
7 19
155 10
Prepared By: Awais Ahmad
12
7 19
155 10
Prepared By: Awais Ahmad
12
7 19
155 10
18
Prepared By: Awais Ahmad
12
7 19
155 10
18
12
7
5 10
18
15 19
Prepared By: Awais Ahmad
12
7
5 10
18
15 19
Prepared By: Awais Ahmad
12
7
5 10
18
15 19
20
Prepared By: Awais Ahmad
12
7
5 10
18
15 19
20
25
Prepared By: Awais Ahmad
12
7
5 10
18
15 19
20
25
Prepared By: Awais Ahmad
12
7
5 10
18
15 20
19 25
Prepared By: Awais Ahmad
12
7
5 10
18
15 20
19 25
23
Prepared By: Awais Ahmad
12
7
5 10
18
15 20
19 25
23
Prepared By: Awais Ahmad
12
7
5 10
20
18 25
2315 19
Prepared By: Awais Ahmad
Prepared By: Awais Ahmad
Prepared By: Awais Ahmad
BS-SE-A
UOG Lahore Campus

More Related Content

Similar to AVL Tree

DS_Mod4_2.pdf
DS_Mod4_2.pdfDS_Mod4_2.pdf
DS_Mod4_2.pdf
SankarTerli
 
4. avl
4. avl4. avl
AVL tree PPT.pptx
AVL tree PPT.pptxAVL tree PPT.pptx
AVL tree PPT.pptx
SamyakJain710491
 
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
 
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
 
Adelson velskii Landis rotations based on
Adelson velskii Landis rotations based onAdelson velskii Landis rotations based on
Adelson velskii Landis rotations based on
banupriyar5
 

Similar to AVL Tree (6)

DS_Mod4_2.pdf
DS_Mod4_2.pdfDS_Mod4_2.pdf
DS_Mod4_2.pdf
 
4. avl
4. avl4. avl
4. avl
 
AVL tree PPT.pptx
AVL tree PPT.pptxAVL tree PPT.pptx
AVL tree PPT.pptx
 
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
 
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
 
Adelson velskii Landis rotations based on
Adelson velskii Landis rotations based onAdelson velskii Landis rotations based on
Adelson velskii Landis rotations based on
 

Recently uploaded

Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 

Recently uploaded (20)

Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 

AVL Tree