SlideShare a Scribd company logo
1 of 35
1Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
AVL Tree
 Definition
 Properties
 Operations
Outline
2Ruli Manurung (Fasilkom UI) IKI10100: Lecture
Balanced binary tree
The disadvantage of a binary search tree is that its
height can be as large as N-1
This means that the time needed to perform insertion
and deletion and many other operations can be O(N)
in the worst case
We want a tree with small height
A binary tree with N node has height at least Θ(log
N)
Thus, our goal is to keep the height of a binary
search tree O(log N)
Such trees are called balanced binary search trees.
Examples are AVL tree, red-black tree.
3Ruli Manurung (Fasilkom UI) IKI10100: Lecture
AVL tree
An AVL 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
4Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
X X
AVL Trees
Unbalanced Binary Search Trees are bad. Worst
case: operations take O(n).
AVL (Adelson-Velskii & Landis) trees maintain
balance.
For each node in tree, height of left subtree and
height of right subtree differ by a maximum of 1.
H
H-1
H-2
5Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
AVL Trees
10
5
3
20
2
1 3
10
5
3
20
1
43
5
6Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
AVL Trees
12
8 16
4 10
2 6
14
7Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
12
8 16
4 10
2 6
14
1
Insertion for AVL Tree
After insert 1
8Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Insertion for AVL Tree
To ensure balance condition for AVL-tree, after
insertion of a new node, we back up the path from the
inserted node to root and check the balance
condition for each node.
If after insertion, the balance condition does not hold
in a certain node, we do one of the following
rotations:
 Single rotation
 Double rotation
9Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Insertions Causing Imbalance
R
P
Q
k1
k2
Q
k2
P
k1
R
An insertion into the subtree:
 P (outside) - case 1
 Q (inside) - case 2
An insertion into the subtree:
 Q (inside) - case 3
 R (outside) - case 4
HP=HQ=HR
10Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
A
k2
B
k1
C
CB
A
k1
k2
Single Rotation (case 1)
HA=HB+1
HB=HC
11Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Single Rotation (case 4)
C
k1
B
k2
A
A B C
k2
k1
HA=HB
HC=HB+1
12Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Q
k2
P
k1
R
R
P
Q
k1
k2
Problem with Single Rotation
Single rotation does not work for case 2 and 3 (inside
case)
HQ=HP+1
HP=HR
13Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
C
k3
A
k1
D
B
k2
Double Rotation: Step
C
k3
A
k1
D
B
k2
HA=HB=HC=HD
14Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
C
k3
A
k1
DB
k2
Double Rotation: Step
15Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
C
k3
A
k1
D
B
k2
C
k3
A
k1
DB
k2
Double Rotation
HA=HB=HC=HD
16Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
B
k1
D
k3
A
C
k2
B
k1
D
k3
A C
k2
Double Rotation
HA=HB=HC=HD
17Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
3
Example
Insert 3 into the AVL tree
11
8 20
4 16 27
8
8
11
4 20
3 16 27
18Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Example
Insert 5 into the AVL tree
5
11
8 20
4 16 27 8
11
5 20
4 16 27
8
19Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
AVL Trees: Exercise
Insertion order:
 10, 85, 15, 70, 20, 60, 30, 50, 65, 80, 90, 40, 5, 55
20Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Remove Operation in AVL Tree
Removing a node from an AVL Tree is the same as
removing from a binary search tree. However, it may
unbalance the tree.
Similar to insertion, starting from the removed node
we check all the nodes in the path up to the root for
the first unbalance node.
Use the appropriate single or double rotation to
balance the tree.
May need to continue searching for unbalanced
nodes all the way to the root.
21Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Deletion X in AVL Trees
Deletion:
 Case 1: if X is a leaf, delete X
 Case 2: if X has 1 child, use it to replace X
 Case 3: if X has 2 children, replace X with its inorder
predecessor (and recursively delete it)
Rebalancing
22Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 55 (case 1)
60
20 70
10 40 65 85
5 15 30 50 80 90
55
23Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 55 (case 1)
60
20 70
10 40 65 85
5 15 30 50 80 90
55
24Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 50 (case 2)
60
20 70
10 40 65 85
5 15 30 50 80 90
55
25Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 50 (case 2)
60
20 70
10 40 65 85
5 15 30
50 80 90
55
26Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 60 (case 3)
60
20 70
10 40 65 85
5 15 30 50 80 90
55
prev
27Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 60 (case 3)
55
20 70
10 40 65 85
5 15 30 50 80 90
28Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 55 (case 3)
55
20 70
10 40 65 85
5 15 30 50 80 90
prev
29Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 55 (case 3)
50
20 70
10 40 65 85
5 15 30 80 90
30Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 50 (case 3)
50
20 70
10 40 65 85
5 15 30 80 90
prev
31Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 50 (case 3)
40
20 70
10 30 65 85
5 15 80 90
32Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 40 (case 3)
40
20 70
10 30 65 85
5 15 80 90
prev
33Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 40 : Rebalancing
30
20 70
10 65 85
5 15 80 90
Case ?
34Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
Delete 40: after rebalancing
30
7010
20 65 855
15 80 90
Single rotation is preferred!
35Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th
Mar 2007
AVL Tree:
The depth of AVL Trees is at most logarithmic.
So, all of the operations on AVL trees are also
logarithmic.
Find element, insert element, and remove element
operations all have complexity O(log n) for worst
case
The worst-case height is at most 44 percent more
than the minimum possible for binary trees.

More Related Content

Recently uploaded

Recently uploaded (20)

Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

data structure on bca.

  • 1. 1Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 AVL Tree  Definition  Properties  Operations Outline
  • 2. 2Ruli Manurung (Fasilkom UI) IKI10100: Lecture Balanced binary tree The disadvantage of a binary search tree is that its height can be as large as N-1 This means that the time needed to perform insertion and deletion and many other operations can be O(N) in the worst case We want a tree with small height A binary tree with N node has height at least Θ(log N) Thus, our goal is to keep the height of a binary search tree O(log N) Such trees are called balanced binary search trees. Examples are AVL tree, red-black tree.
  • 3. 3Ruli Manurung (Fasilkom UI) IKI10100: Lecture AVL tree An AVL 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
  • 4. 4Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 X X AVL Trees Unbalanced Binary Search Trees are bad. Worst case: operations take O(n). AVL (Adelson-Velskii & Landis) trees maintain balance. For each node in tree, height of left subtree and height of right subtree differ by a maximum of 1. H H-1 H-2
  • 5. 5Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 AVL Trees 10 5 3 20 2 1 3 10 5 3 20 1 43 5
  • 6. 6Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 AVL Trees 12 8 16 4 10 2 6 14
  • 7. 7Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 12 8 16 4 10 2 6 14 1 Insertion for AVL Tree After insert 1
  • 8. 8Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Insertion for AVL Tree To ensure balance condition for AVL-tree, after insertion of a new node, we back up the path from the inserted node to root and check the balance condition for each node. If after insertion, the balance condition does not hold in a certain node, we do one of the following rotations:  Single rotation  Double rotation
  • 9. 9Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Insertions Causing Imbalance R P Q k1 k2 Q k2 P k1 R An insertion into the subtree:  P (outside) - case 1  Q (inside) - case 2 An insertion into the subtree:  Q (inside) - case 3  R (outside) - case 4 HP=HQ=HR
  • 10. 10Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 A k2 B k1 C CB A k1 k2 Single Rotation (case 1) HA=HB+1 HB=HC
  • 11. 11Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Single Rotation (case 4) C k1 B k2 A A B C k2 k1 HA=HB HC=HB+1
  • 12. 12Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Q k2 P k1 R R P Q k1 k2 Problem with Single Rotation Single rotation does not work for case 2 and 3 (inside case) HQ=HP+1 HP=HR
  • 13. 13Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 C k3 A k1 D B k2 Double Rotation: Step C k3 A k1 D B k2 HA=HB=HC=HD
  • 14. 14Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 C k3 A k1 DB k2 Double Rotation: Step
  • 15. 15Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 C k3 A k1 D B k2 C k3 A k1 DB k2 Double Rotation HA=HB=HC=HD
  • 16. 16Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 B k1 D k3 A C k2 B k1 D k3 A C k2 Double Rotation HA=HB=HC=HD
  • 17. 17Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 3 Example Insert 3 into the AVL tree 11 8 20 4 16 27 8 8 11 4 20 3 16 27
  • 18. 18Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Example Insert 5 into the AVL tree 5 11 8 20 4 16 27 8 11 5 20 4 16 27 8
  • 19. 19Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 AVL Trees: Exercise Insertion order:  10, 85, 15, 70, 20, 60, 30, 50, 65, 80, 90, 40, 5, 55
  • 20. 20Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Remove Operation in AVL Tree Removing a node from an AVL Tree is the same as removing from a binary search tree. However, it may unbalance the tree. Similar to insertion, starting from the removed node we check all the nodes in the path up to the root for the first unbalance node. Use the appropriate single or double rotation to balance the tree. May need to continue searching for unbalanced nodes all the way to the root.
  • 21. 21Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Deletion X in AVL Trees Deletion:  Case 1: if X is a leaf, delete X  Case 2: if X has 1 child, use it to replace X  Case 3: if X has 2 children, replace X with its inorder predecessor (and recursively delete it) Rebalancing
  • 22. 22Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 55 (case 1) 60 20 70 10 40 65 85 5 15 30 50 80 90 55
  • 23. 23Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 55 (case 1) 60 20 70 10 40 65 85 5 15 30 50 80 90 55
  • 24. 24Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 50 (case 2) 60 20 70 10 40 65 85 5 15 30 50 80 90 55
  • 25. 25Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 50 (case 2) 60 20 70 10 40 65 85 5 15 30 50 80 90 55
  • 26. 26Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 60 (case 3) 60 20 70 10 40 65 85 5 15 30 50 80 90 55 prev
  • 27. 27Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 60 (case 3) 55 20 70 10 40 65 85 5 15 30 50 80 90
  • 28. 28Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 55 (case 3) 55 20 70 10 40 65 85 5 15 30 50 80 90 prev
  • 29. 29Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 55 (case 3) 50 20 70 10 40 65 85 5 15 30 80 90
  • 30. 30Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 50 (case 3) 50 20 70 10 40 65 85 5 15 30 80 90 prev
  • 31. 31Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 50 (case 3) 40 20 70 10 30 65 85 5 15 80 90
  • 32. 32Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 40 (case 3) 40 20 70 10 30 65 85 5 15 80 90 prev
  • 33. 33Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 40 : Rebalancing 30 20 70 10 65 85 5 15 80 90 Case ?
  • 34. 34Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 Delete 40: after rebalancing 30 7010 20 65 855 15 80 90 Single rotation is preferred!
  • 35. 35Ruli Manurung (Fasilkom UI) IKI10100: Lecture 27th Mar 2007 AVL Tree: The depth of AVL Trees is at most logarithmic. So, all of the operations on AVL trees are also logarithmic. Find element, insert element, and remove element operations all have complexity O(log n) for worst case The worst-case height is at most 44 percent more than the minimum possible for binary trees.