SlideShare a Scribd company logo
1 of 13
Chapter 10
Search Structures
   AVL Trees
Introduction
• Searching on dynamic tables
  – Insert/delete symbols from the set
  – Using a binary search to maintain
     • Eg. JAN, Feb, …
                                  # comp. to find “NOV” = 6
                                  Avg. # comp. = 42/12 = 3.5




      Entering in a different order…
Enter months to Generate Balanced tree
• A balanced tree: JUL, FEB, MAY, …




• Any path from root-to-leaf is of the same
  length (balanced) // vs. the skewed tree
  – Max. # of id. Comparisons = 4, avg.=37/12
Form a Tree (degenerate to a chain)
• Lexicographic order

                        Max. # = 12
                        Avg. = 6.5
Objective
• Minimize (Max. & avg. search) time if the
  binary tree is complete at all time
• To maintain that by re-structuring will
  cause some insertions time-consuming
• It is possible to maintain a balanced tree!
• Avg. / worst case retrieval time O(log n)
• Adelson-Velskii-Landis binary
  – Balanced with respect to heights of sub-trees
     • O(log n): insert/delete/retrieve
Definition
• Height-balanced tree
  – (1) Empty tree is height-balanced
  – (2) non-empty binary tree T, left-subtree TL,
    right-subtree TR:
    T is height-balanced if
     (i) TR and TL are height-balanced
     (ii) |hL – hR| ≤ 1 where hL and hR are the heights of TR and
       TL
• Balance factor
  – BF(T) = hL – hR
  – BF(T) = -1, 0, or 1for any node in an AVL tree
Construct AVL Tree
• Insert order: MAR, MAY, NOV, …
• Monitor BF(*), Rotate if necessary
  –   (1) RR
  –   (2) LL
  –   (3) LR
  –   (4) RL
Example
Example (cont.)
Example (cont.)
Example (cont.)
Example (cont.)
Memo.
• Nearest ancestor A, inserted node Y
  – LL
     • Y insert A’s L-subtree’s L-subtree
  – LR
     • Y insert A’s L-subtree’s L-subtree
  – RR
     • Y insert A’s R-subtree’s R-subtree
  – RL
     • Y insert A’s R-subtree ‘s L-subtree

More Related Content

What's hot (20)

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
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
1.7 avl tree
1.7 avl tree 1.7 avl tree
1.7 avl tree
 
Circular queue
Circular queueCircular queue
Circular queue
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
 
Binomial queues
Binomial queuesBinomial queues
Binomial queues
 
File organization 1
File organization 1File organization 1
File organization 1
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Data preprocessing
Data preprocessingData preprocessing
Data preprocessing
 
stack & queue
stack & queuestack & queue
stack & queue
 
Big Data Evolution
Big Data EvolutionBig Data Evolution
Big Data Evolution
 
Threaded Binary Tree
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
 
File organization
File organizationFile organization
File organization
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Leftist heap
Leftist heapLeftist heap
Leftist heap
 

Similar to Avl trees

Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphRai University
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graphRai University
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graphRai University
 
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binarySSE_AndyLi
 
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.pdfMuhammadUmerIhtisham
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptxTekle12
 
Skiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure treesSkiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure treeszukun
 
Algo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.pptAlgo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.pptHebaSamy22
 
Generation of Rooted Trees & Free Trees
Generation of Rooted Trees & Free TreesGeneration of Rooted Trees & Free Trees
Generation of Rooted Trees & Free TreesPurbashaChowdhury7
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAdityaK92
 
Data structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxData structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxAhmedEldesoky24
 

Similar to Avl trees (20)

Mca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graphMca iii dfs u-4 tree and graph
Mca iii dfs u-4 tree and graph
 
Bca ii dfs u-3 tree and graph
Bca  ii dfs u-3 tree and graphBca  ii dfs u-3 tree and graph
Bca ii dfs u-3 tree and graph
 
Bsc cs ii dfs u-3 tree and graph
Bsc cs  ii dfs u-3 tree and graphBsc cs  ii dfs u-3 tree and graph
Bsc cs ii dfs u-3 tree and graph
 
7 chapter4 trees_binary
7 chapter4 trees_binary7 chapter4 trees_binary
7 chapter4 trees_binary
 
tree.ppt
tree.ppttree.ppt
tree.ppt
 
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
 
chapter 6.1.pptx
chapter 6.1.pptxchapter 6.1.pptx
chapter 6.1.pptx
 
Skiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure treesSkiena algorithm 2007 lecture05 dictionary data structure trees
Skiena algorithm 2007 lecture05 dictionary data structure trees
 
Algo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.pptAlgo-Exercises-2-hash-AVL-Tree.ppt
Algo-Exercises-2-hash-AVL-Tree.ppt
 
Generation of Rooted Trees & Free Trees
Generation of Rooted Trees & Free TreesGeneration of Rooted Trees & Free Trees
Generation of Rooted Trees & Free Trees
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Data structures 3
Data structures 3Data structures 3
Data structures 3
 
Red Black Trees
Red Black TreesRed Black Trees
Red Black Trees
 
Short dec
Short decShort dec
Short dec
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
 
Tree
TreeTree
Tree
 
Tree.pptx
Tree.pptxTree.pptx
Tree.pptx
 
Data Structures 4
Data Structures 4Data Structures 4
Data Structures 4
 
Data structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptxData structures and Algorithm analysis_Lecture4.pptx
Data structures and Algorithm analysis_Lecture4.pptx
 

More from Mohd Arif

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcpMohd Arif
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarpMohd Arif
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocolMohd Arif
 
Project identification
Project identificationProject identification
Project identificationMohd Arif
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniquesMohd Arif
 
Presentation
PresentationPresentation
PresentationMohd Arif
 
Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peerMohd Arif
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systemsMohd Arif
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdpMohd Arif
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgetingMohd Arif
 
Network management
Network managementNetwork management
Network managementMohd Arif
 
Networing basics
Networing basicsNetworing basics
Networing basicsMohd Arif
 
Iris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformIris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformMohd Arif
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and sslMohd Arif
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psecMohd Arif
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardwareMohd Arif
 

More from Mohd Arif (20)

Bootp and dhcp
Bootp and dhcpBootp and dhcp
Bootp and dhcp
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarp
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
 
Project identification
Project identificationProject identification
Project identification
 
Project evalaution techniques
Project evalaution techniquesProject evalaution techniques
Project evalaution techniques
 
Presentation
PresentationPresentation
Presentation
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Peer to-peer
Peer to-peerPeer to-peer
Peer to-peer
 
Overview of current communications systems
Overview of current communications systemsOverview of current communications systems
Overview of current communications systems
 
Overall 23 11_2007_hdp
Overall 23 11_2007_hdpOverall 23 11_2007_hdp
Overall 23 11_2007_hdp
 
Objectives of budgeting
Objectives of budgetingObjectives of budgeting
Objectives of budgeting
 
Network management
Network managementNetwork management
Network management
 
Networing basics
Networing basicsNetworing basics
Networing basics
 
Loaders
LoadersLoaders
Loaders
 
Lists
ListsLists
Lists
 
Iris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platformIris ngx next generation ip based switching platform
Iris ngx next generation ip based switching platform
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and ssl
 
Ip security in i psec
Ip security in i psecIp security in i psec
Ip security in i psec
 
Intro to comp. hardware
Intro to comp. hardwareIntro to comp. hardware
Intro to comp. hardware
 
Heap sort
Heap sortHeap sort
Heap sort
 

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 

Avl trees

  • 2. Introduction • Searching on dynamic tables – Insert/delete symbols from the set – Using a binary search to maintain • Eg. JAN, Feb, … # comp. to find “NOV” = 6 Avg. # comp. = 42/12 = 3.5 Entering in a different order…
  • 3. Enter months to Generate Balanced tree • A balanced tree: JUL, FEB, MAY, … • Any path from root-to-leaf is of the same length (balanced) // vs. the skewed tree – Max. # of id. Comparisons = 4, avg.=37/12
  • 4. Form a Tree (degenerate to a chain) • Lexicographic order Max. # = 12 Avg. = 6.5
  • 5. Objective • Minimize (Max. & avg. search) time if the binary tree is complete at all time • To maintain that by re-structuring will cause some insertions time-consuming • It is possible to maintain a balanced tree! • Avg. / worst case retrieval time O(log n) • Adelson-Velskii-Landis binary – Balanced with respect to heights of sub-trees • O(log n): insert/delete/retrieve
  • 6. Definition • Height-balanced tree – (1) Empty tree is height-balanced – (2) non-empty binary tree T, left-subtree TL, right-subtree TR: T is height-balanced if (i) TR and TL are height-balanced (ii) |hL – hR| ≤ 1 where hL and hR are the heights of TR and TL • Balance factor – BF(T) = hL – hR – BF(T) = -1, 0, or 1for any node in an AVL tree
  • 7. Construct AVL Tree • Insert order: MAR, MAY, NOV, … • Monitor BF(*), Rotate if necessary – (1) RR – (2) LL – (3) LR – (4) RL
  • 13. Memo. • Nearest ancestor A, inserted node Y – LL • Y insert A’s L-subtree’s L-subtree – LR • Y insert A’s L-subtree’s L-subtree – RR • Y insert A’s R-subtree’s R-subtree – RL • Y insert A’s R-subtree ‘s L-subtree